Hi all,
I created a script to make a crosshair that changes color when a raycast hits an object with a different tag ("Friend" or "Enemy") That worked fine, however the raycast shoots forwards on the world axis, so if the object is forward to me on the world axis, no matter where I face, the crosshair changes color.
The object I have it attached to is the camera on a FPS character (So the parent rotates on the x axis, and it rotates on the y). Here's part of my script:
var crosshairRange = 200;
private var hit : RaycastHit;
private var facingDirection = Vector3.forward;
function Update ()
{
if (Physics.Raycast(transform.position, facingDirection, hit, crosshairRange))
{
if (hit.collider.gameObject.CompareTag("Enemy"))
{
enemyHit = 1;
}
etc.
My guess is the problem is with either the private variable 'facingDirection' or 'transform.position' bit , but I don't know what the problem is.
Any help would be appreciated!