Im new to Unity and coding in C# in general. I’ve been trying to make the ball I have in
my game return to its original position after it stops moving. I just can’t seem to make this
work for whatever reason. I’ve experimented on my own, looked online in the forums, on
YouTube, and still got nothing. Any solution will be much appreciated. Code is down below:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BallControl : MonoBehaviour
{
private Vector3 originalPos;
private float speed;
public Vector3 velocity;
private new Rigidbody gameObject;
public new Vector3 transform;
void OnTriggerEnter(Collider other)
{
if (other.name == "Cup")
{
Debug.Log("COMPLETE!");
}
}
void Update()
{
speed = gameObject.velocity.magnitude;
if (speed < 0.5)
{
Reset();
}
}
void Reset()
{
gameObject.transform.position = originalPos;
}
void Start()
{
originalPos = gameObject.transform.position;
}
}