- Home /
Question by
cyth1 · Jul 05, 2015 at 09:42 PM ·
rigidbodyontriggerentersleep
Can't use Rigidbody.Sleep() because I need to reference an object?
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
}
}
}
Comment
Answer by tanoshimi · Jul 05, 2015 at 09:43 PM
Rigidbody is a class. You want the instance of that class attached to this Gameobject.
GetComponent<Rigidbody>().Sleep();
Your answer
![](https://koobas.hobune.stream/wayback/20220611225929im_/https://answers.unity.com/themes/thub/images/avi.jpg)