Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Storing References to GameObjects

Discussion in 'iOS and tvOS' started by guillopuyol, Apr 18, 2014.

  1. guillopuyol

    guillopuyol

    Joined:
    Jul 16, 2013
    Posts:
    10
    Hello,

    I'm trying to store references to game objects in a script, but when I reference the .gameObject I get the holder rather than the original script.

    For Example:

    in gameController I have a reference to the castleCamera game object.

    if I do castleCamera.camera it says gameController does not have a camera, but I'm actually trying to access the camera attached to the original game object castleCamera.

    I'm confused with this one... can somebody shed some light on this?
     
  2. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    instead of .camera, try castleCamera.GetComponent<Camera>();

    I think .camera is a shortcut method to something else. Oh, and by the way, this should be in the scripting forum, not iOS.