- Home /
effect of an object when mouseover
When an object(which import from 3DSMAX) mouseover
I want it looks a bit different (for example show border or lighten)
what script should I use?
I am using
public class example : MonoBehaviour { void OnMouseEnter() { } }
for mouseover function
thx for your help
i am trying this method to change
using UnityEngine; using System.Collections;
public class example : $$anonymous$$onoBehaviour { public Shader shader1 = Shader.Find("Diffuse"); public Shader shader2 = Shader.Find("Transparent/Diffuse"); void Update() { if (Input.GetButtonDown("Jump")) if (renderer.material.shader == shader1) renderer.material.shader = shader2; else renderer.material.shader = shader1;
}
}
but nothing comes out... how come
Answer by darkcookie · Apr 07, 2012 at 06:23 AM
try this it makes the object red
var initialColor : Color;
function Start()
{
initialColor = renderer.material.color;
}
function OnMouseOver()
{
renderer.material.color = Color.red;
}
function OnMouseExit()
{
renderer.material.color = initialColor;
}
i think i find the problem...
it works after i add the collider...but i really dunno what is collider stand for
however thanks for your reply
as for a collider just ad a box collider and you should be fine....*note colliders can be used as triggers or for physics
here come a question
I have a group of objects and I want to mouseover either one and the whole group will change color
I put the script to the group but doesnt work...so do i need to write script for every single one?
well no just call the function GameObject.FindWithTag (tag name)
http://unity3d.com/support/documentation/ScriptReference/GameObject.FindWithTag.html