Hi,I’m creating a survival shooter game.I have 3 script target,gun and score board.I’m trying to do score = 10 change health 60 or + 10 but changed moment object is health is not decreasing,pls help.
public float damage = 5f;
public float range = 100f;
public float fireRate = 15f;
public Camera fpsCam;
public ParticleSystem Muzzle;
public void Button_Click ()
{
if (Input.GetButton("Fire1"))
{
Shoot();
}
}
public void OnPointerDown()
{
InvokeRepeating("Shoot", 0, 0.2f);
}
public void OnPointerUp()
{
CancelInvoke("Shoot");
}
void Shoot ()
{
Muzzle.GetComponent<ParticleSystem>().Play();
RaycastHit hit;
if(Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
{
Debug.Log(hit.transform.name);
Target target = hit.transform.GetComponent<Target>();
if(target != null)
{
target.TakeDamage(damage);
}
}
}
and
public float health;
public void Update()
{
if (ScoreScript.scoreValue == 10)
{
health = 60f;
}
}
public void TakeDamage (float amount)
{
health -= amount;
if(health <= 0f)
{
ScoreScript.scoreValue += 10;
Die();
}
}
void Die()
{
Destroy(gameObject);
}
}