- Home /
Question by
ubisun · Mar 05, 2017 at 03:26 PM ·
scripting problemscript.scripting beginnerscriptingbasics
how can I change a light with multiple triggers. ?
Hi,
I'm quite new to unity and scripting and i'm having issues with a script. I'm trying to make the color of te light change when I trigger a cube, for now i managed to do it with to different scripts, one attached to the trigger cube :
using UnityEngine;
using System.Collections;
public class triggertest : MonoBehaviour {
public float rouge ;
public float vert ;
public float bleu ;
void OnTriggerEnter(Collider col ) {
rouge = Random.Range (0f, 1f);
vert = Random.Range (0f, 1f);
bleu = Random.Range (0f, 1f);
Debug.Log (rouge);
Debug.Log (vert);
Debug.Log (bleu);
}
}
and the other attached to the light :
using UnityEngine;
using System.Collections;
public class light : MonoBehaviour {
public Light lt;
public GameObject trigger;
private triggertest script;
private float rouge2;
private float vert2;
private float bleu2;
void Start() {
lt = GetComponent<Light> ();
lt.color = Color.HSVToRGB(Random.Range(0f,1f),Random.Range(0f,1f),Random.Range(0f,1f));
script = trigger.GetComponent<triggertest> ();
}
void Update() {
//rouge2 = GameObject("cube").triggertest.rouge;
rouge2 = script.rouge;
vert2 = script.vert;
bleu2 = script.bleu;
lt.color = Color.HSVToRGB(rouge2,vert2,bleu2);
}
}
I tried to make just one script, for the trigger but it doesn't work. Anyone have any ideas why ?
using UnityEngine;
using System.Collections;
public class unique : MonoBehaviour {
public Light lt;
public float rouge;
public float vert;
public float bleu;
void Start() {
lt = GetComponent<Light> ();
lt.color = Color.HSVToRGB(Random.Range(0f,1f),Random.Range(0f,1f),Random.Range(0f,1f));
}
void OnTriggerEnter(Collider col ) {
rouge = Random.Range (0f, 1f);
vert = Random.Range (0f, 1f);
bleu = Random.Range (0f, 1f);
Debug.Log (rouge);
Debug.Log (vert);
Debug.Log (bleu);
}
void Update() {
lt.color = Color.Color.HSVToRGB(rouge,vert,bleu);
}
}
Thank you in advance
Comment