- Home /
Raycast error
Please help me it doesn't show eny errors but it doesn't work.
here is script:
using UnityEngine;
using System.Collections;
public class RockPickUp : MonoBehaviour {
void Update () {
var fwd = transform.TransformDirection(Vector3.forward);
RaycastHit hit;
if (Physics.Raycast(transform.position, fwd, out hit))
{
if(hit.distance <= 5.0 && hit.collider.gameObject.tag == "PickUp")
{
//I want the pick up script so when you come closer to the rock and pres E it shoes +1 in my inventory,
//i know how to do the inventory stuff but i don't know raycast please help
}
}
}
}
Comment
Your problem may lie in your forward vector. You use Vector3.foward, which is always (0,0,1). You could try using this.transform.forward, but I'm not sure what this script is attached to. Say the character's head was rotating to face the rock, you want to forward of that.
Answer by alexander11 · Dec 18, 2014 at 07:52 AM
i think this is the problem
if (Physics.Raycast(transform.position, fwd, out hit, 100))
just by adding the 100 at the end may help
Your answer
Follow this Question
Related Questions
Raycasting in script suddenly stopped working 1 Answer
Need help with this error 2 Answers
(2D) Raycast check - null reference even when (RayHit != null) 2 Answers
LookRotation and Raycasting 2 Answers