I am working on unity2d. I have six game objects:
Object1, Object2, Object3 (these are images)
ObjectImage1, ObjectImage2, ObjectImage3 (these are images).
I have arranged the object in the scene as a list one below another
Object1
Object2
Object3
When I click the
Object1 ---> should change to ObjectImage1
Object2 ---> should change to ObjectImage2, but the above image of object1(objectImage1) at present should change to Object1
Object3 ---> should change to ObjectImage3,but the above image on object2(objectImage2) should change to Object2
This is similar to selection. My code is as follows:
public GameObject newSprite;
private Vector3 currentSpritePosition;
void Start()
{
newSprite.renderer.enabled = false; //then make it invisible
currentSpritePosition = transform.position; //give the new sprite the position of the latter
renderer.enabled = false; //then make it visible
newSprite.transform.position = currentSpritePosition;
newSprite.renderer.enabled = true;
}
void OnMouseExit()
{
//just the reverse process
renderer.enabled = true;
newSprite.renderer.enabled = false;
}
This is the code used to change the material:
public GameObject newSprite;
private Vector3 currentSpritePosition;
void Start(){
newSprite.renderer.enabled = false;
}
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;
}
Currently when I click on Object2 it changes to ObjectImage2 but the first object is not changing to Object1 from ObjectImage1.
onMouseEnter()
to handle clicks? You probably wantonMouseUp()
. – layzrr Aug 27 at 14:48