I’m trying to finish this bullet shell script so they can eject whenever I shoot, and I came across this error when using Rigidbody.Sleep:
“An object reference is required to access non-static member `UnityEngine.Rigidbody.Sleep()'”
All I know is the prefab I’m using is not static but
using UnityEngine;
using System.Collections;
public class Shell : MonoBehaviour {
private float lifeTime = 5;
private Material mat;
private Color originalCol;
private float fadePercent;
private float fadeTime;
private bool fading;
void Start () {
mat = GetComponent<Renderer>().material;
originalCol = mat.color;
fadeTime = Time.time + lifeTime;
StartCoroutine ("Fade");
}
IEnumerator Fade()
{
while (true) {
yield return new WaitForSeconds(.2f);
if (fading){
fadePercent += Time.deltaTime;
mat.color = Color.Lerp (originalCol,Color.clear,fadePercent);
if (fadePercent >= 1){
Destroy(gameObject);
}
}
if (Time.time > fadeTime){
fading = true;
}
}
}
void OnTriggerEnter(Collider c){
if (c.tag == "Ground") {
Rigidbody.Sleep(); // <-- This is my problem
}
}
}