HELP: My cube 'snaps' to the floor and does not drop!

I’ve been looking at this from all angles. I even made a completely new cube and rewrote the entire code, but nothing seems to be working. Every time I hit ‘play’ the cub will wait three seconds and then ‘snap’ to the ground. It doesn’t actually drop.

Here is the entire code I have on the cube:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Dropper : MonoBehaviour

{

MeshRenderer renderer;

Rigidbody rigidBody;

[SerializeField] float timeToWait = 3f;

void Start()

{

    renderer = GetComponent<MeshRenderer>();

    rigidBody = GetComponent<Rigidbody>();

    renderer.enabled = false;

    rigidBody.useGravity = false;

}
void Update()

{

    if (Time.time > timeToWait)

    renderer.enabled = true;

    rigidBody.useGravity = true;

}

}

SOMETHING ELSE. At random points when I hit ‘play’ the cube will fall instantly, actually engaging the gravity, but NOT the mesh renderer. I am beyond confused at this point XD

FIGURED IT OUT

I missed two curly braces at the bottom of the code!

if (Time.time > timeToWait)

{
renderer.enabled = true;
rigidBody.useGravity = true;
}

Yay! XD

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms