Help me with gui please (C#)
Hi Guys, I have had this problem for a while. Basiclly i am making 2d platform game and i am trying to make it so when the player hits the finish flag
the gui show up.
i already have a script for this but it never works i dont know why. FYI i have just started learning c#
Thank You
The Script
using UnityEngine;
using System.Collections;
public class Level_Finish : MonoBehaviour {
public GUITexture finishFlag;
void Start () {
finishFlag.enabled = false;
}
void OnTriggerEnter(Collider col){
if (col.tag == "Player") {
finishFlag.enabled = true;
}
}
}
You need to add that script to the flag object that has the collider on it.
http://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.OnTriggerEnter.html
Answer by Iplaydev1 · May 14, 2016 at 10:52 PM
Use OnTriggerEnter2D().
How does that help if the normal OnTriggerEnter is not working?
Woops, forgot to add code.
void OnTriggerEnter2D(Collider2D other) {
if (other.CompareTag("Player")) {
finishFlag.setActive(true);
}
}
Cheers, mate.
Answer by Gaming-Dudester · May 16, 2016 at 04:05 AM
Try this
using UnityEngine; using System.Collections;
public class Level_Finish : MonoBehaviour {
public GUITexture finishFlag;
void Start () {
finishFlag.enabled = false;
}
void OnTriggerEnter2D(Collider2D col){
if (col.tag == "Player") {
finishFlag.enabled = true;
}
}
}
make sure your character is tagged "Player" and that your flag has "istrigger" turned on under the boxcollider(or circle or polygon or edge collider) and make sure you assign the guitexture in the editor and also make sure the script is on. The problem is OnTriggerEnter doesn't work on 2d games. u need OnTriggerEnter2D and (Collider2D col).
Your answer
Follow this Question
Related Questions
Doodle Jump Game Platform Spawn Issue Unity2D 0 Answers
Player Can Not get off platform 1 Answer
Stepping on game object moves quickly to react 0 Answers
Detect the objects staying on top of the Particles 0 Answers
Setting up a function for sorting specific triggers entered based on a height integer. 0 Answers