hey at all, i need some help (once more)
i want a plane with a crosshair texture to be displayed when the enemy object is hitten by a raycast from the player ( if foundhit = true) it basically works but not continiously while its being hitten. it’s displayed for a short moment, then it disappears, then it is displayed again for a short moment (and so on) while the ray hits the enemy. seems it’s because of the update funct. certainly i tried to set it to : while(foundhit = true) and certainly unity stucked.
how to achiefe that it is displayed while! the ray hits ?
thx previously
here’s the code:
using UnityEngine;
using System.Collections;
public class Crosshair : MonoBehaviour {
public Transform raytrf;
public float raycastDist = 1000.0f;
public string tagCheck = "Enemy";
public bool foundHit;
public bool checkAllTags = true;
RaycastHit crosshair_hit;
//private Renderer rend;
public GameObject thisplane;
// Use this for initialization
void Start ()
{
//rend = GetComponent<Renderer> ();
//rend.enabled = false;
}
// Update is called once per frame
void Update ()
{
//bool foundHit = false;
RaycastHit crosshair_hit = new RaycastHit();
foundHit = Physics.Raycast(transform.position, transform.forward, out crosshair_hit, raycastDist);
//Vector3 forward = raytrf.TransformDirection(Vector3.forward.normalized) * 1000;
//Debug.DrawRay(raytrf.position,forward, Color.red);
if (foundHit && checkAllTags && crosshair_hit.transform.tag != tagCheck)
{
foundHit = false;
//rend.enabled = false;
}
if (!foundHit)
{
thisplane.layer = LayerMask.NameToLayer ("Invisible");
//rend.enabled = false;
//Debug.Log("false");
}
else
{
if(foundHit)
{
thisplane.layer = LayerMask.NameToLayer ("Default");
//rend.enabled = true;
//Debug.Log("hit");
}
}
}
}