Hello,
I have made a soccer / football game and I wrote a script that resets my ball whenever it touches one of the goal boxes I added in the game but I can’t figure out how to reset the player’s position at the same time.
Here is the script :
using UnityEngine;
using System.Collections;
public class BallManager : MonoBehaviour
{
public int Score1;
public int Score2;
public void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Goal1")
{
transform.position = GameObject.Find("BallPosition").transform.position;
this.gameObject.GetComponent<Rigidbody>().Sleep();
Score1 += 1;
}
if (other.gameObject.tag == "Goal2")
{
transform.position = GameObject.Find("BallPosition").transform.position;
this.gameObject.GetComponent<Rigidbody>().Sleep();
Score2 += 1;
}
}
public void Update()
{
GameObject.Find("Score1").GetComponent<TextMesh>().text = Score1 + "";
GameObject.Find("Score2").GetComponent<TextMesh>().text = Score2 + "";
}
}
Not exactly a good answer because restarting Unity isn't a great solution so I'll convert this to a comment.
– allenallenallen