Help with Raycast Script
Hi,
I'd like to create a simple NPC system, when the player character walks up to an NPC, an icon pops up, allowing the player to talk to them. I am using raycasting to detect whether the player is near an NPC or not. However, my code has a few errors:
using UnityEngine;
using System.Collections;
public class collisionDetection : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
RaycastHit hit;
Ray landingRay = new Ray(transform.position, Vector3.left);
Debug.DrawRay(transform.postion, Vector3.left * deploymentHeight);
if (Physics.Raycast(landingRay.direction out hit, 20))
{
if(hit.collider.tag == "npc")
{
print("There is an NPC, ayyy")
}
}
}
}
Console is saying unexpected symbol 'out' If someone could tell me what is wrong with my code, and how to fix it that would be great Cheers :)
And if you put a comma somewhere between the word direction and the word out?
if (Physics.Raycast(landingRay.direction, out hit, 20))
like that. Not got access to Unity so debugging in my head (which rarely goes well!).
Your answer
Follow this Question
Related Questions
Raycast is going through collider (A plane) 0 Answers
Raycast shooting, child collider call and detection 0 Answers
Raycast hits Ray origin, possibly, randomly. 2 Answers
raycasthit to set new move location 0 Answers
RayCast2D and RayDraw errors 0 Answers