So I have a script that shows an icon near interactable Objects. The Script is put onto a sprite. As soon as the Script is put onto another Sprite the script stops working. More specifically the Renderer stays disabled. As long as there is only one sprite that holds the script everything works perfectly. Here is the code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InteractableIconScript : MonoBehaviour {
public GameObject InteractableObject;
public GameObject Player;
public Transform target;
public float dis;
public float RenderDis;
public static Renderer rend;
public static Animator anim;
public Vector3 offset;
private int Fired = 0;
void Awake()
{
rend = GetComponent<Renderer>();
rend.enabled = false;
anim = GetComponent<Animator>();
transform.position = InteractableObject.transform.position + offset;
}
// Update is called once per frame
void Update () {
dis = Vector3.Distance(InteractableObject.transform.position, Player.transform.position);
transform.LookAt(target);
if ((dis < RenderDis) && (Fired < 1))
{
rend.enabled = true;
anim.Play("IconPlop");
Fired = 1;
}
else if (dis > RenderDis)
{
rend.enabled = false;
Fired = 0;
}
}
}