I just started on Unity a few weeks ago and I got a cube to fall from a random position, but when it hits the ground, I lose control of my player for some reason. The two are in no way connected, so I’m very confused right now. Any suggestions?
Falling Object Script:
public class CubeFall : MonoBehaviour {
// Use this for initialization
void Start () {
Vector3 pos = transform.position;
pos.x = Random.Range(-10, 10);
pos.y = 50;
pos.z = Random.Range(-10, 10);
transform.position = pos;
}
}
Player Controls:
public class PlayerController : MonoBehaviour
{
public float speed;
public Text countText;
public Text winText;
private Rigidbody rb;
private int count;
void Start()
{
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Pick Up"))
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText();
speed = count/2;
}
}
void SetCountText()
{
countText.text = "Count: " + count.ToString();
if (count >= 12)
{
winText.text = "You Win!";
}
}
}
Yes these are modifications I’m making based off the original Roll a Ball tutorial. Super new here.