Search Unity

How to Change Properties of Assigned Objects?

Discussion in 'Scripting' started by Miggl, Aug 22, 2013.

  1. Miggl

    Miggl

    Joined:
    Aug 20, 2013
    Posts:
    13
    Hi, I am very new to unity, please bear with me. I am trying to change properties of GameObjects that have been assigned to public script variables in my script. Unfortunately the changes in my script are not visible in game mode, or they aren't taking. To better illustrate, here is my script:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class Torch : MonoBehaviour
    6. {
    7.     public Light TorchLight;
    8.     public Color LightColor;
    9.  
    10.     void Start ()
    11.     {
    12.         //this assignment doesn't seem to be working, the light still shines with its original color.
    13.         this.TorchLight.color = this.LightColor;
    14.     }
    15.    
    16.  
    17.     void Update ()
    18.     {
    19. //[...]
    20.     }
    21.    
    22.     void OnMouseDown()
    23.     {
    24. //[...]
    25.     }
    26. }
    27.  
     
    Last edited: Aug 22, 2013
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,411
    That code works for me.. light color changes when you press play (and have the script in some object in scene).
     
  3. chelnok

    chelnok

    Joined:
    Jul 2, 2012
    Posts:
    680
    yep.. looks fine, and tested; works fine.
     
  4. Miggl

    Miggl

    Joined:
    Aug 20, 2013
    Posts:
    13
    Thanks for looking at this. Sorry to put you through this, I tried it on another computer with a new scene, and it did work. Thanks again :)