var playercamera ; Rigidbody;

Hallo,

i have the following script which works fine, but i want to save much work for me.
I have to attach this script to many many Gameobjects and i dont want to drag´n´drop the var Rigidbody to every single attached script.

How can i change the code, that the var is always the same ? :?:

]var Spielerkamera : Rigidbody;

function Update(){

    
    var dist = Vector3.Distance(Spielerkamera.position, transform.position);
    print ("Distance to other: " + dist);

	if (dist > 20){
		renderer.enabled = false;
					}

	if (dist < 20){
		renderer.enabled = true;	
					}	

}

EDIT: in other words, the “var Spielerkamera : Rigidbody” should always be a certain Rigidbody

You can add:

var Awake(){
Spielerkamera =GameObject.Find("NAME").GetComponent(RigidBody);
}

Where name is the gameobjects name, that has the rigidbody. You could also search for this gameobject by giving it a tag…and Awake() could also be Start().

Thanks for your reply, i´ll try that.