Question by
dragonking300 · Dec 31, 2016 at 04:48 PM ·
c#scripting beginner
What Identifyier like other in collision scripts can I use in my raycast script to refer to the object my ray is hitting
I really need to know what I could use as a identifier to refer to the object my ray hits in my raycast script
What I want my script to do: I want my script to detect if a the wall in-front of the camera is lets say 30 meters in-front of it and if it is the wall will have its opacity changed to 50% and once the wall is not 30 meters in-front of it the wall will return to 100% opacity.
my script
using UnityEngine; using System.Collections;
public class CameraControll : MonoBehaviour { Vector3 Campos; public Transform player; public GameObject Player; int count = 0; public float Distance;
public void Update()
{
RaycastHit hit;
Ray LandingRay = new Ray(transform.position, Vector3.forward);
if(Physics.Raycast(LandingRay, out hit, Distance))
{
if(hit.collider.tag == "wall")
{
if(transform.position - hit.collider.transform.position == Vector3(0, 30, 0))
{
}
}
}
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;
}
}
}
}
}
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612103803im_/https://answers.unity.com/themes/thub/images/avi.jpg)