Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Help with my game

A topic by Carlkbh created Aug 26, 2021 Views: 320 Replies: 7
Viewing posts 1 to 4

i want to make it so that when i press an object it disappears/appears i cant find any explanation on how to do this, pls help

Submitted

this should help you forward with the clicking part

c# - onClick event for Image in Unity - Stack Overflow

Submitted

and the dissapearing is just linking the sprite or mesh renderer and disabeling or enabeling it

thanks

(1 edit)

ok so i did what you said

but it still doesnt work,


this is my code

{

    public void Activate()

    {

        gameObject.SetActive(false);

    }

}

Hi Carlkbh.

How do you refer to this object?

Do you declare it publicly and attach it in Unity or do you find it with a tag or name?

If you wont mind showing us the whole script can help a lot more than just a function.

(1 edit)

i used the eventtricker function

Take a look at the code from the manual.


using UnityEngine; 
using UnityEngine.UI; 
using System.Collections;
public class ClickExample : MonoBehaviour 
{ 	
  public Button yourButton; // Put your button in here
  void Start () 
  { 		
    Button btn = yourButton.GetComponent<Button>(); 		
    btn.onClick.AddListener(TaskOnClick); 
    //When the button gets clicked/pressed it will call TaskOnClick() function below	
  }
  void TaskOnClick()
  { 		
    Debug.Log ("You have clicked the button!"); 	
  } 
}
I hope this helps.
I've struggled with this same topic a while ago 
and this helps