Hey there.I am making a 3d game but i am facing an issue.I have a vase and i want to de-activate it and activate another item when i click the vase(both of them with 1 click). Here is my code but for some reason when i write the code to de-activate the 2nd item, the script won’t work :
using UnityEngine;
using System.Collections;
public class TreasureItemsHandler : MonoBehaviour {
public GameObject treasureitem;
//public GameObject floatingisland_1;
// Disabling the treasureitem when clicked!
void OnMouseDown()
{
treasureitem.SetActive(false);
//floatingisland_1.SetActive(true);
}
}
EDIT : The floatingisland item is de-activated in the scene!
i meant to say in my post that i want to de-activate the vase and activate the other item… should i change my code or nope?That’s why i have it on false
ok, you click on the treasure, which means that your code should look like this…
using UnityEngine;
using System.Collections;
public class SwapTo : MonoBehaviour {
public GameObject swapTo;
// Disabling the treasureitem when clicked!
void OnMouseDown()
{
gameObject.SetActive(false);
swapTo.SetActive(true);
}
}
Thanks so much it worked now ! But where was my mistake?Was it that i instead of using gameobject.setactive for the treasure i used treasureitem.setactive… ?
Also can i make them both de-activate and activate slowly? like fade in?Do i need a coroutine ?