- Home /
The question is answered, right answer was accepted
Problem with multiple scripts
I have two scripts, one which control my guiText on screen and another which handles the bull of the firing mechanics.
What i would like is to increase my score every time i destroy an enemy but as of now it happens every time i fire. Anyone able to help me out?
Here is some of my cannon script:
if (Input.GetButtonDown("Fire1"))
{
Rigidbody clone;
clone = Instantiate(projectile, transform.position + offset, transform.rotation) as Rigidbody;
clone.velocity = transform.TransformDirection(Vector3.forward * force);
if(clone.gameObject.tag == "bullet")
{
Destroy(clone.gameObject, destroyTime);
//I want to add score here
accelShotHS.score += 1;
}
}
Here is the GUIText script:
public class accelShotHS : MonoBehaviour
{
public static int score;
public GUIText text;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
guiText.text = "Score: " + score;
}
}
Answer by KMKxJOEY1 · Aug 11, 2014 at 09:54 PM
move this:
//I want to add score here
accelShotHS.score += 1;
to an event where the bullet collides with the enemy. You have it set to do that every time a bullet times out
Argh i had it where I thought I was destroying the enemy, ins$$anonymous$$d of where i actually destroyed him. I feel quite stupid now :/ Thanks for the help
Answer by GLADUS · Aug 11, 2014 at 10:03 PM
Im not a very good programer, and im just a beginner, but you could add a collider to the enemy and use ontriggerenter to destroy and add a point.
Follow this Question
Related Questions
3D Text Size Relative To Screen? 4 Answers
Ngui with Unity Remote 4 1 Answer
Text pop up when mouse over gui button 2 Answers
gui text mirrored 2 Answers