Answers for "unity adding component to another gameobject"

C#
1

unity adding component to another gameobject

//referencing a gameobject
public GameObject exampleObject;
//===============================================================>
private Rigidbody rb; //example of a component

public void Awake() {
	// adding a Rigidbody component to exampleObject
	rb = exampleObject.AddComponent<Rigidbody>();
  
	// referencing an existing Rigidbody component in exampleObject
	rb = exampleObject.GetComponent<Rigidbody>();
}
Posted by: Guest on May-06-2020

Code answers related to "unity adding component to another gameobject"

C# Answers by Framework

Browse Popular Code Answers by Language