Answer the question
In order to leave comments, you need to log in
C# character enhancement code in Unity. Can you help?
Hello! I have two questions at once
. Introduction: I started developing a clicker with monsters and heroes. When it came to improving the DPS (damage per second) hero, the problems started. I made a bool, which means that the character has already appeared and the question arose how to make it so that it is activated when the character appears? I left this problem for later since bool is public and I could enable it manually for now. And I immediately ran into the second problem, namely, that after I bought this character, he appeared and started shooting, I turned on bool UpTime and by pressing the button the money is removed, but the character does not improve! I IMMEDIATELY SORRY FOR THE CURVE CODE, I'M A BEGINNER and I throw off all the code to make it easier for you to understand
(I searched for information for 2 days and did not find anything, I really need your help)
Questions: 1. How to enable bool on button click?
2. How to make the character improve?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UpButtonHelper : MonoBehaviour
{
public Text DamageText;
public Text PriceText;
public int Damage = 1;
public int Price = 10;
public bool IsHero;
public bool IsRuby;
public bool UpTime;
public GameObject HeroPrefab;
public float X, Y, Z, Mult;
GameHelper _gameHelper;
HeroHelper _heroHelper;
BulletHelper _bulletHelper;
// Start is called before the first frame update
void Start()
{
_gameHelper = GameObject.FindObjectOfType<GameHelper>();
_heroHelper = GameObject.FindObjectOfType<HeroHelper>();
_bulletHelper = GameObject.FindObjectOfType<BulletHelper>();
DamageText.text = "+" + Damage.ToString();
PriceText.text = Price.ToString();
}
// Update is called once per frame
void Update()
{
DamageText.text = "+" + Damage.ToString();
PriceText.text = Price.ToString();
}
public void UpClick()
{
if (!IsRuby && _gameHelper.PlayerGold >= Price || IsRuby && _gameHelper.PlayerRuby >= Price)
{
if (!IsRuby)
{
_gameHelper.PlayerGold -= Price;
}
else
{
_gameHelper.PlayerRuby -= Price;
}
if (IsHero == false)
{
_gameHelper.PlayerDamage += Damage;
}
else
{
if (UpTime == false)
{
GameObject hero = Instantiate(HeroPrefab) as GameObject;
Vector2 heroPos = new Vector2(X, Y);
hero.transform.position = heroPos;
}
_heroHelper.Damage += Damage;
Damage = Damage * 2;
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question