Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
1.3 kB
2
Indexable
public class WallMaterial : MonoBehaviour
{
    public Transform targetObject;
    public GameObject gameObject;

    [SerializeField]

    private LayerMask wallMask;


    public Material holeMaterial, wallMaterial;
    Renderer renderer;
    

    private void Start()
    {
        gameObject.GetComponent<Renderer>().material = wallMaterial;
    }

    private void Update()
    {
        
        var direction = targetObject.position - transform.position;
        float distance = Vector3.Distance(transform.position, targetObject.position);
        RaycastHit hit;
        


        if (Physics.Raycast(transform.position, direction, out hit, distance))
        {
            
            Debug.Log("vittuje vitut");
            renderer = hit.transform.GetComponent<Renderer>();
            Debug.Log("take the renderer");
            gameObject.GetComponent<Renderer>().material = holeMaterial; // TODO make it work
            
            Debug.Log("there's a hole");
        }
        else
        {
            if (renderer != null)
            {
                gameObject.GetComponent<Renderer>().material = wallMaterial; // TODO
                Debug.Log("no holes found");
            }
        }
        
    }
}