- Home /
The AI-Players do not see new install (Instantiate) object (the ball) after they set the first goal in gates and old object (the ball) was destroyed.
We have available two soccer commands red and blue. We have the ball. His name is CubeBall. CubeBall have Tag=Player in Inspector. All AI-Players have parameter Target = CubeBall(Transform) in script in Inspector. AI-Players touch this CubeBall before the first goal in Gate. We have two gate - the GATE_B and GATE_R. For eхample, goal has set to GATE_B.
Code:
private var GolToBlue = 0;
private var CubeBall:GameObject;
function OnTriggerEnter(GATE_B : Collider) {
if (GATE_B.gameObject.name == "CubeBall")
{
GolToBlue++ ;
Destroy(GameObject.Find("CubeBall"), 5);
Instantiate(GameObject.Find("CubeBall"), Vector3(7,2,-30), transform.rotation);
}
}
function OnGUI() {
// G-O-O-L to BLUE GATE !!!
GUI.color=Color.red;
GUI.Label(Rect(50,50,100,100),GolToBlue.ToString());
}
This work beautifully visual, BUT AI-players do not touch this CubeBall now? Play goes before first goal :) What me to do ???