- Home /
enable a canvas on trigger
i have a problem,im planning on making a parking game to release on gamejolt,and i dont know how to make a trigger enable a canvas, i've tried everything but nothing worked,when i tried to make a script it gave me an error, it said unexpected symbol end of file,i need someone to make a script that doesent give me an error.
Answer by InfixionGames · Apr 20, 2019 at 08:03 PM
I am asuming that you are making a 2d game. If you are making a 3d game remove the 2D from the onTrigger and Collider. Make sure that you have a collider on the gameObject and set it to trigger and a rigidbody. If this isn't what you are looking for could you be more clear with your question. For example when do you want the canvas to be enabled and how, via a button, collision, key press using System.Collections; using System.Collections.Generic; using UnityEngine;
public class EnableCanvas : MonoBehaviour
{
//The canvas you want to enable
public GameObject canvas;
//Check if something has entered the collider this script is on
void OnTriggerEnter2D(Collider2D other)
{
//Check if the object has the tag car
if(other.tag == "car")
{
//Activate the canvas
canvas.SetActive(true);
}
}
}
wait a just a $$anonymous$$ute im making a 3d game not a 2d game
Does it not work when you remove the 2D from OnTriggerEnter2D and Collider2D?
yep it doesnt work because when i tried test the script you wrote it gave me a message saying the other script required was not found
Answer by xephosmmb122 · Apr 21, 2019 at 08:29 PM
Hi I hope this can help you,`
public GameObject canvasHolder = GameObject.Find("Canvas"); private GameObject canvasGameHolder;[
canvasGameHolder = Instantiate(canvasHolder);
`