I’m trying to make a camera script that fades when ever the camera gets close to a wall obstructing the view of the player and the main problem is I can’t change the color becuase Idk what I am doing, how do I change the color?
using UnityEngine;
using System.Collections;
public class CameraControll : MonoBehaviour
{
Vector3 Campos;
public Transform player;
public GameObject Player;
int count = 0;
public float Distance;
private GameObject block;
public void Update()
{
Vector3 Direction = Player.transform.position - transform.position;
RaycastHit hit;
Ray LandingRay = new Ray(transform.position, Vector3.forward);
Debug.DrawRay(transform.position, Direction * Distance);
if (Physics.Raycast(LandingRay, out hit, Distance))
{
if(hit.collider.tag == "Wall")
{
Debug.Log("close");
block = hit.collider.transform.parent.gameObject;
block.GetComponent<Renderer>().material.color.a = 0.5; //help please ;-;
}
else
{
Debug.Log("Far");
block = hit.collider.transform.parent.gameObject;
block.GetComponent<Renderer>().material.color.a = 1;
}
}
if (Input.GetKeyDown("q"))
{
count++;
}
else
{
if (Input.GetKeyDown("e"))
{
count--;
}
}
transform.position = Player.transform.position + Campos;
transform.LookAt(player);
}
public void LateUpdate()
{
if (count == 0)
{
Campos = new Vector3(0f, 5f, -7f);
Debug.Log(count);
}
else
{
if (count == 1)
{
Campos = new Vector3(7f, 5f, 0f);
Debug.Log(count);
}
else
{
if (count == 2)
{
Campos = new Vector3(0f, 5f, 7f);
Debug.Log(count);
}
else
{
if (count == 3)
{
Campos = new Vector3(-7f, 5f, 0);
Debug.Log(count);
}
else
{
if (count <= -1)
{
count = 3;
}
else
{
if (count <= 4)
{
count = 0;
}
}
}
}
}
}
}
}