I’m having issues getting this to work. My peach was falling but was not disappearing like it should have and I got an error stating:
MissingComponentException: There is no ‘MeshRenderer’ attached to the “Peach” game object, but a script is trying to access it.
You probably need to add a MeshRenderer to the game object “Peach”. Or your script needs to check if the component is attached before using it.
Dropper.Start () (at Assets/Scripts/Dropper.cs:16)"
I checked and there was indeed no Mesh Renderer on the peach, so I added that and it still does not work correctly. During play, Mesh Renderer is disabled but the peach doesn’t disappear and won’t fall. When I remove Mesh Renderer it starts falling again.
My code so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Dropper : MonoBehaviour
{
MeshRenderer renderer;
Rigidbody rigidbody;
[SerializeField] float timeToWait = 5f;
// Start is called before the first frame update
void Start()
{
renderer = GetComponent<MeshRenderer>();
rigidbody = GetComponent<Rigidbody>();
renderer.enabled = false;
rigidbody.useGravity = false;
}
// Update is called once per frame
void Update()
{
if(Time.time > timeToWait)
{
Debug.Log("3 seconds have elapsed");
}
}
}