Question by
pandagamingroyt · Aug 03, 2020 at 11:20 AM ·
gamereset-positionfootball
How to reset player position when a ball hits the goal box?
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 + "";
}
}
Comment
Your answer
Follow this Question
Related Questions
How to reset player positions after a goal 0 Answers
Unity/Mapbox Location Based Game "Tile Overlay" / "Fog of war" 0 Answers
How to speed up building at game? 1 Answer
Jacks game Simulator 0 Answers