unity 3d student

Beginner B17 – Tweaking Components via script

How to find and adjust components on other objects using GetComponent().

Code Used (Javascript)

function OnCollisionEnter (myCollision : Collision) {
  1.  if(myCollision.gameObject.name == "Floor"){
  2.   var myLight : Light = gameObject.Find("Light").GetComponent(Light);
  3.    myLight.enabled = true;
  4.    myLight.intensity = 5;
  5.  }
  6. }

Further Reading

Share via Social Media

  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • Add to favorites

39 Comments