Transform.Position Wrong Execute
public class Respawn : MonoBehaviour { private Vector3 StartPoint;
// Use this for initialization
void Start () {
StartPoint = this.transform.position;
}
void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Respawn"))
{
//transform.position = StartPoint;
//SceneManager.LoadScene("SampleScene");
transform.position = StartPoint;
//this.transform.position = StartPoint + new Vector3(Random.Range(-7f, 1f), -7f, 1f);
}
}
Hi I put the walls out of the game screen as you see in the video and the picture. I want to reset the position when I hit the top walls, ie when I go out of the game but the position is reset but this is constantly repeating.Because if the ball strikes the walls and hits the walls I want it to return to the first place.I do not want to replay the scene, Score: "The score is reset when you play the scene again because of the score, so there is no other solution?
what the hell are you even asking? the ball naturally falls out of the scene at which point its position is set back to its original position. nothing you said made any sense.
what I can tell you is that the ball is falling because of the Rigidbody2D attached to it. The Gravity on the Rigidbody is probably 1 which means it is applied. When you reset the position you don't reset the velocity of the rigidbody meaning that it continues to speed up and eventually would go very fast. you could solve this problem by going:
// make it start with a velocity of 0
GetComponent<Rigidbody> ().velocity = 0;