Hey everyone.
Currently I have an odd situation where it (appears) at least that Update is not getting called at all.
I will get straight to it and show some code as there is not much else to say.
This is the offending Update that is not getting called even though the Start does.
using UnityEngine;
using System.Collections;
public class CameraFacingBillboard : MonoBehaviour
{
public Camera m_Camera;
void Start()
{
if(m_Camera == null)
m_Camera = Camera.main;
}
void Update()
{
transform.LookAt(transform.position + m_Camera.transform.rotation * Vector3.forward, m_Camera.transform.rotation * Vector3.up);
Debug.Log("Update Called!");
}
}
I create a canvas with this code. (The canvas is world space and has the Billboard look at script on it.)
using UnityEngine;
using System.Collections;
namespace CarlH{
namespace Tooltips{
public class ItemTooltip : MonoBehaviour {
public float heightOffset = 1f;
GameObject canvas;
public void ActivateTooltip(){
if(canvas != null)
canvas.SetActive(true);
else
CreateCanvas();
}
public void DeactivateTooltip(){
if(canvas != null)
canvas.SetActive(false);
else
CreateCanvas();
}
void CreateCanvas()
{
GameObject tooltipCanvas = (GameObject)Resources.Load("PickupCanvas");
Vector3 spawnPos = new Vector3(transform.position.x, transform.position.y + heightOffset, transform.position.z);
canvas = (GameObject)Instantiate(tooltipCanvas, spawnPos, transform.rotation);
canvas.transform.SetParent(transform, true);
}
}
}
}
I detect how to activate/deactivate the canvas using this script:
using UnityEngine;
using System.Collections;
namespace CarlH{
namespace Tooltips{
public class DetectItem : MonoBehaviour {
GameObject hitPickupCache;
void Update () {
RaycastHit hit;
if(Physics.Raycast(transform.position, transform.forward, out hit, 5f)){
if(hit.transform.gameObject.tag == "Pickup"){
if(hitPickupCache != null){
hitPickupCache.GetComponent<ItemTooltip>().DeactivateTooltip();
hitPickupCache = hit.transform.gameObject;
}
else{
hitPickupCache = hit.transform.gameObject;
}
hit.transform.gameObject.GetComponent<ItemTooltip>().ActivateTooltip();
if(Input.GetKeyDown(KeyCode.E)){
Destroy(hit.transform.gameObject);
}
}
else if(hitPickupCache != null){
hitPickupCache.GetComponent<ItemTooltip>().DeactivateTooltip();
}
}
else if(hitPickupCache != null){
hitPickupCache.GetComponent<ItemTooltip>().DeactivateTooltip();
}
}
}
}
}
The canvas spawns correctly and even funnier, it was actually working a few minutes ago.
Tried restarting Unity so I dont know what it could be.
(Im using Unity 5.4 official release)