When I run this script in Unity: (ignore the clones variable)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Throw : MonoBehaviour
{
public Rigidbody rb;
private float clones = 0;
public KeyCode throwKey = KeyCode.Mouse0;
private void Update()
{
if (transform.parent != null)
{
gameObject.name = "Wood";
rb.isKinematic = true;
if (Input.GetKeyDown(throwKey))
{
Vector3 position = new Vector3(transform.parent.position.x, transform.parent.position.y, transform.parent.position.z);
Instantiate(gameObject, position, Quaternion.Euler(0, 0, 0));
rb.AddForce(transform.forward * 500f, ForceMode.Impulse);
transform.SetParent(null);
StartCoroutine(Wait());
}
}
else
{
gameObject.name = "thrownWood";
rb.isKinematic = false;
}
}
IEnumerator Wait()
{
yield return new WaitUntil(Input.GetKeyUp(throwKey));
}
}
It comes up with the error message:
Any idea for why this happens?
