I have 4 empty game objects from which to launch balls ( like Crash Bash Ballistix )but after the first ball is launched ( Start ) nothing happens. It works if i attach 4 scripts to these objects but that’s lame and I want it all in one while attached to some other object like arena.
public Rigidbody Ball;
private float Timer = 0;
private Rigidbody newBall = null;
public GameObject Launch1;
public GameObject Launch2;
public GameObject Launch3;
public GameObject Launch4;
void Start () {
newBall = Instantiate(Ball, Launch1.transform.position, transform.rotation) as Rigidbody;
newBall.AddForce (new Vector3 (-220, 0, -150));
}
void Update()
{
Timer += Time.deltaTime;
if (Timer == 40) {
newBall = Instantiate (Ball, Launch1.transform.position, transform.rotation) as Rigidbody;
newBall.AddForce (new Vector3 (-22, 0, -15));
Timer = 0;
}
else if (Timer == 30) {
newBall = Instantiate (Ball, Launch2.transform.position, transform.rotation) as Rigidbody;
newBall.AddForce (new Vector3 (-22, 0, -15));
}
else if (Timer == 20) {
newBall = Instantiate (Ball, Launch3.transform.position, transform.rotation) as Rigidbody;
newBall.AddForce (new Vector3 (-22, 0, -15));
}
else if (Timer == 10) {
newBall = Instantiate (Ball, Launch4.transform.position, transform.rotation) as Rigidbody;
newBall.AddForce (new Vector3 (-22, 0, -15));
Debug.Log ("YOLO");
}
}
}