- Home /
Question by
dragonking300 · Dec 31, 2016 at 02:38 AM ·
c#scripting beginner
How would I use other without it being a collision script
I've seen people use "other" as a way to refrence the object the collider is colliding with but how would I use that in my raycast 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" && transform.position - transform.position.out) // how would I put other in here
{
}
}
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
Answer by arkrp · Dec 31, 2016 at 09:55 AM
just a guess but GameObject other = hit.colider.gameObject;
Error CS0019 Operator '&&' cannot be applied to operands of type 'bool' and 'Vector3'
Answer by UnityCoach · Jan 03, 2017 at 12:01 PM
Depends how you want to use it.
if(hit.collider.tag == "wall" && (transform.position - hit.collider.transform.position) <= 1)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How would I make a ListChangedEvent? 1 Answer
How to detect right answer or not 0 Answers
Reference Variables and Drag-And-Drop 0 Answers