- Home /
Object modified in script not modified in scene
Hello guys, I have a problem, and I don't know how to solve it.
I have a very basic code : using UnityEngine; using System.Collections;
public class LightBallScript : ObjectScript {
bool isRed = false;
Renderer rend;
void Start () {
rend = GetComponent <Renderer> ();
rend.material.EnableKeyword ("_Emission");
}
public override void ActivateObject () {
if (isRed) {
Debug.Log ("red --> black");
rend.material.SetColor ("_Emission", Color.black);
rend.material.SetFloat ("_Emission", 0);
isRed = false;
} else {
Debug.Log ("black --> red");
rend.material.SetFloat ("_Emission", 1);
rend.material.SetColor ("_Emission", Color.red);
Debug.Log (rend.material.GetColor ("_Emission"));
isRed = true;
}
transform.position.Set (transform.position - Vector3.up);
}
}
My player calls the method ActivateObject. I checked that it was called with a debug.log . With debug.log, I checked that the gameobject was a "LightBall" (basically a sphere) and that the material was the "LightBall Material". I also checked that the emission color was changed to red.
But, in the scene, none of these modifications occured : the lightball didn't move, nor change its color.
I never got any problem like that, so I don't know where to search.
Thanks for your answers !
Your answer
![](https://koobas.hobune.stream/wayback/20220611231447im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
What is Mono? Is it a compiler? A language? Or what? 3 Answers
What is Vector3, Vector4, etc.? 2 Answers
Does Unity support multiple Inheritance? 3 Answers
Player kill enemy by stepping on it. 2 Answers