1

I have an object that changes its color when it collides with another object, and decreases its size: gameObject.transform.localScale /= 2; but it has a white halo.

I want the halo to match my object's color. So when the object is a green color, so also the halo will be green as well. And if my object is blue, then the halo will be blue as well. Also, I want that when my object detect collision with other object, halo also decrease and I don't know how can I do it.

Code change color (blue, red or green) when I press the screen:

public class ChangeColor : MonoBehaviour {

    public Material[] materials;
    public Renderer rend;

    private int index = 1;

    // Use this for initialization
    void Start () {

        rend = GetComponent<Renderer> ();
        rend.enabled = true;

    }

    public void Update() {
        if (materials.Length == 0) {
            return;
        }
        if (Input.GetMouseButtonDown (0)) {
            index += 1;

            if (index == materials.Length + 1) {
                index = 1; 
            }
            print (index);

            rend.sharedMaterial = materials [index - 1];                        
        }
    }
}

I know use halo but programatically I don't know.

Chuck Savage
  • 11,775
  • 6
  • 49
  • 69
Rf Mvs
  • 166
  • 11
  • Looking at your last two questions and this one, I suggest you learn the [basic part](https://unity3d.com/learn/tutorials) of Unity and [programming](https://unity3d.com/learn/tutorials/topics/scripting). You can do this with the [`if`](https://unity3d.com/learn/tutorials/topics/scripting/if-statements?playlist=17117) statement. You must understand the basic first. I am also saying this because the code in your question does not even come close to doing what you expect to do. – Programmer Nov 13 '16 at 16:29
  • 1
    i know , programmer, this only change the color! i need the halo! – Rf Mvs Nov 13 '16 at 16:31
  • programatically ``halo`` i don't know how use it. – Rf Mvs Nov 13 '16 at 16:32
  • can you help me please with this? – Rf Mvs Nov 13 '16 at 16:33
  • **"So when the object is a green color, so also the halo will be green as well. And if my object is blue, then the halo will be blue as well. Also, I want that when my object detect collision with other object, halo also decrease"**. Please tell me which part you are having problem with? Changing color? Comparing Color? Detecting Collision? You don't even have any of this in your question.Please, read my first comment. **"halo also decrease"** I think you should explain this more in your question. Happy coding! – Programmer Nov 13 '16 at 16:41
  • Ok, my object decrease his size but it has incorporate ``halo``. This halo can't decrease ! I want my halo decrease like my object. – Rf Mvs Nov 13 '16 at 17:05

1 Answers1

0

This Halo Component is accessible with a bit of work, let me demonstrate it with code.

Private void Start() {   
    SerializedObject haloComponent = new SerializedObject(this.gameObject.GetComponent("Halo"));
    haloComponent?.FindProperty("m_Color").colorValue = Color.Red;
}

There are some more things you can do but this is the way to get a reference to the Halo. Keep in mind GetComponent<> is searching for something that is Halo and GetComponent("Halo") is searching for something with the name Halo. Since the Component is named Halo it works like a charm. Try it out