- Home /
Question by
xDevily · Aug 20, 2014 at 05:35 PM ·
c#gameobject
change a gameobject into another
I need to transform one object into another one. I have this object into my menu:
when i put the mouse cursor on it i want that it becomes like this:
and than when the user put the mouse cursor out of the object it return to be the button (1st immage).
How can i code this in c#?
Comment
Best Answer
Answer by Hexer · Aug 20, 2014 at 05:53 PM
http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseEnter.html
Use OnMouseEnter and OnMouseExit.
public GameObject newSprite;
private Vector3 currentSpritePosition;
void OnMouseEnter(){
//getting the current position of the current sprite if ever it can move;
currentSpritePosition = transform.position;
//then make it invisible
renderer.enabled = false;
//give the new sprite the position of the latter
newSprite.transform.position = currentSpritePosition;
//then make it visible
newSprite.renderer.enabled = true;
}
void OnMouseExit(){
//just the reverse process
renderer.enabled = true;
newSprite.renderer.enabled = false;
}
http://stackoverflow.com/questions/24669630/change-the-sprite-when-mouse-over
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Glow single Object 1 Answer
How to SetTrigger all colliders with a specific name 1 Answer