public Image not working C#
I have been stuck on this for a very long time, I am trying to create one of the boxes that show up in the inspector that you can drop gameobjects into, and I have created the following script:
using UnityEngine; using System.Collections;
public class Radar : MonoBehaviour {
public Image Arrow;
void OnTriggerEnter( Collider other) {
if (other.gameObject.tag == "Enemy")
Arrow.SetActive(true);
}
}
The part with "public Image" is what is causing the problem, I have looked at other successful scripts that use this statement, but mine will not work, HELP!
The error I recieve is the following: The type or namespace name 'Image' could not be found (are you missing a using directive or an assembly reference?)
@Guhanesh does this method still work or is it different for the 2019 version
Answer by Guhanesh · Apr 29, 2016 at 05:58 AM
SetActive can only be used for GameObjects.What do you mean by Image datatype? If you are refering Image component of a gameobject,if so your script should be like this.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Radar : MonoBehaviour {
public Image Arrow;
void OnTriggerEnter( Collider other) {
if (other.gameObject.tag == "Enemy")
Arrow.gameObject.SetActive(true);
}
}
THAN$$anonymous$$ YOU! That was the answer. Thank you so much!
Welcome.If my answer was helpful , you could mark it as correct or upvote it.just for the karma points :)
Your answer
Follow this Question
Related Questions
how do i make the player walk the direction the camera looks at 1 Answer
Input.GetAxisRaw always returns -0.6 1 Answer
SmoothDamp bug? 0 Answers
[SOLVED] Player prefab not spawning 2 Answers