Question by
TellusG · Apr 28, 2020 at 01:42 PM ·
raycastif-statementsassign-variable
Raycast goes into if statement its not suppose to?!
I'm making a twinskick zombie shooter for a schoolproject and to be able to see my character behind a wall i decided to create a raycast that deactivates the rendering for it. The code works almost fine xcept for when i would step underneath a light and it would assign my obstruction var to my player???? using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; using UnityEngine;
public class CameraWall : MonoBehaviour {
public Transform obstruction;
public GameObject target;
// Start is called before the first frame update
void Start()
{
target = GameObject.Find("Player");
}
// Update is called once per frame
void LateUpdate()
{
_ViewObstructed();
}
void _ViewObstructed()
{
RaycastHit hit;
if (Physics.Raycast(transform.position, target.transform.position - transform.position, out hit, 20f))
{
if (hit.collider.gameObject.tag != "Player" && hit.collider.gameObject.tag != "NotTransparent")
{
obstruction = hit.transform;
obstruction.gameObject.GetComponent<MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.ShadowsOnly;
}
else
{
obstruction.gameObject.GetComponent<MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;
}
}
}
}
Comment