- Home /
Problems with tags
Hello, I have 2 images with different tags (let's say image1 has tag1 and image2 has tag2). When I drag the image1 to the place where the OnTriggerEnter is, I want an image to appear that says it's correct. When I drag the image2 I want an image to appear that says it's wrong. I have managed the images to appear OnTrigger...The problem is that those images appear both at the same time, no matter if I drag image1(tag1) or image2(tag2). The result is the same. It's like Unity does not recognize their tags at all.
Here is the code for the correct match:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CorrectMatch : MonoBehaviour {
public Image img;
public string givenTag;
// Use this for initialization
void Start () {
img.enabled = false;
}
public void Recon()
{
if (tag == givenTag) {
}img.enabled = true;//enables the image that says its correct
}
}
Here is the code for the wrong match:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Wrong : MonoBehaviour {
public Image image;
public string imgTag;
// Use this for initialization
void Start () {
image.enabled = false;
}
public void Reject()
{
if (tag != imgTag) {
image.enabled = true;//enables the image that says it's wrong
}
}
}
At the Inspector I have added an Event Trigger, a Pointer Enter basically which has the functions Recon() and Reject. I don't understand what's wrong here.
Answer by pihels · Apr 05, 2020 at 01:04 PM
Perhaps because iIn the first script img.enabled = true; is outside the if block so it is called every time.
Actually the line img.enabled = true; is inside the if block.
if (tag == givenTag) {
}img.enabled = true;//enables the image that says its correct
That looks like its is outside to me (this is in the Correct$$anonymous$$atch class)... I dont know how your scene is set up, but i imagine both of those scripts are on the same object? And it always displays the 'image that says its correct' image? In this case the first script will always fire so..
Yes both of the scripts are attached on the same object.
Your answer
Follow this Question
Related Questions
OntriggerEnter / Stay with the same Gameobject tags 0 Answers
How to put a image under a powerbar's handle thats moving? 0 Answers
I want to change the player's ball velocity by entering transparence3D Objects 2 Answers
Question: Is it possible to create an image out of an HTML canvas in unity using c#? 0 Answers
My instanced projectiles will not trigger the OnTriggerEnter command on enemies 2 Answers