- Home /
 
 
               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
              
 
               
               
               Best Answer 
              
 
              Answer by pradeep_vimap · Aug 04, 2020 at 06:19 AM
@pandagamingroyt you have to sleep or static rigidbody first then assign new position. and also make sure its not a child if its a child then you use localPosition instead of position.
Your answer
 
             Follow this Question
Related Questions
getting udp package info inside unity (GlovePIE) 0 Answers
Selling Games made with Free Assets 4 Answers
lightmapping vs realtime for racing cars 0 Answers
link to open website 1 Answer