Hi all, so I have a script as below, which gets no errors but does not do what I want it to do, I am trying to add 1 int to the score var in the Shoot script from this script, but it adds multiples to the score var in the Shoot script, would anyone know how I can fix this. Thank you.
using UnityEngine;
using System.Collections;
public class TargetHealthA : MonoBehaviour
{
public float health = 35f;
public Animation targetDown;
public float lessOne = 0.1f;
public int addOne = 1;
public Shoot addScore;
void Start()
{
targetDown = GetComponent<Animation> ();
addScore = GetComponent<Shoot> ();
}
public void RemoveHealth(float enemyDamage)
{
health -= enemyDamage;
}
void Update()
{
if (health <= 0)
{
Dead ();
}
}
void Dead()
{
Shoot.score += 1;
targetDown.Play ("TargetDownA");
Destroy (gameObject, 0.5f);
}
}
I have already tried to use using
using UnityEngine;
using System.Collections;
public class TargetHealthA : MonoBehaviour
{
public float health = 35f;
public Animation targetDown;
public float lessOne = 0.1f;
public Shoot addScore;
void Start()
{
targetDown = GetComponent<Animation> ();
addScore = GetComponent<Shoot> ();
}
public void RemoveHealth(float enemyDamage)
{
health -= enemyDamage;
}
void Update()
{
if (health <= 0)
{
Dead ();
}
}
void Dead()
{
GetComponent<Shoot>(), AddScore();
targetDown.Play ("TargetDownA");
Destroy (gameObject, 0.5f);
}
}
For the line GetComponent(),AddScore(); I do not know what is meant to go infront of this, I have searched through Answers but most responses are about how to set it up as in void Start varName = GetComponent();, but dont explain how to access the script through another function.
The Shoot Script is about 600 lines long so I cant post it here, but everything works perfectly in it bar adding the 1 int when the Target is hit, but here is the section for the score
void Update()
{
scoreText.text ="Score : "+ score.ToString
}
public void AddScore(int addScore)
{
score += addOne;
}'
As I say when I use Shoot.score += 1 from the first script shown I get multiples adding to the score not just 1 int as I am looking for. Could someone please explain to me how to fix these issues. Thank you. Joxer