Hey,
So, Wen i run the game in the editor it works perfectly, but wen i have build the game it the raycast doen nothing at all and doesn’t work
Is this a Bug?
Or is it just my script?
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using UnityEngine;
public class InteractScript : MonoBehaviour {
public float InteractDistance = 5;
public KeyCode InteractKey;
public GameObject InteractObject;
public bool InteractObjeState = false;
RaycastHit hit;
void Start()
{
}
void Update ()
{
//-----------------------------------------------------------------------------
if (InteractObjeState == false)
{
InteractObject.SetActive(false);
}
if (InteractObjeState == true)
{
InteractObject.SetActive(true);
}
//-----------------------------------------------------------------------------
Ray ray = new Ray(transform.position, transform.forward);
RaycastHit hit;
if(Physics.Raycast(ray, out hit, InteractDistance))
{
if(hit.collider.CompareTag("LootAble"))
{
InteractObjeState = true;
if (Input.GetKeyDown(InteractKey))
{
hit.collider.gameObject.GetComponent<ItemId>().Enter();
InteractObjeState = false;
}
}
else
{
InteractObjeState = false;
}
}
//-----------------------------------------------------------------------------
}
}
All Help is Welcome!