Solve it by solving the other errors, it’s simply not bothering to update the parameter check because other things are going wrong. Changing all of your “hit.rigidbody” calls to “hit.transform.GetComponent()” or something instead may help.
Try going into your actual error console and see what the very first error in the list is, rather than using the in-line errors. Errors tend to cascade, so you should solve the first one then re-check.
if (Input.GetMouseButtonDown(0)) {
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit)){
}
}
the problem is i have invalid argument in Physics.Raycast (Ray yourRay, out RaycastHit yourHit) but based on this http://docs.unity3d.com/ScriptReference/RaycastHit-point.html it have second parameter out RaycastHit but when i tried that it gives me an error. Also i tried to use .point on ray and there’s no autocomplete for that…
The problem is NOT with this code, again- unless you’re just missing an additional } or something after this. Please go into your Unity console and check the list of errors, and screenshot them, then post it back here. Not just the errors with this script, but the errors with the whole project. Verify which one is listed first.
i’m pretty sure that i’m not missing something like } or anything like that. As you can see at the picture below, this is my whole script and it doesn’t have any realation with another script.
And this picture shows the second parameter that has out RaycastHit
and lastly the errors from compiling
you can try http://docs.unity3d.com/ScriptReference/RaycastHit-point.html and see it yourself
clean blank project, add cube, add the below… works fine. Got to be something else outside this code.
using UnityEngine;
using System.Collections;
public class TestScript : MonoBehaviour
{
void Update()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
Debug.Log(hit.point);
}
}
}
}
okay okay… i feel so dumb here…
so i just restarted the unity and the monodevelop, and it’s still give me that shit
by the way im using unity 5.1.1f1.
So what’s wrong with my unity ?
I have absolutely no idea. Try making sure that you have a camera tagged “Main Camera” in the scene, and uhh… shut down Unity and delete the “Library” folder in your project folder (a cache) to see if maybe that’s doing something funky. Back everything up first, just to be safe…
The only other record I can find with someone having this problem says that the following day it simply fixed itself. That could point to the cache idea being valid, or something a little deeper but just as temporary. Try restarting your computer?
only other thing i can think it might be is; all the screen shots you’ve posted are from the script editor, is unity throwing the same errors in the console? might just be a problem with monodevelop or whatever scripting ide you’re using (weird mac screenshots shudders :P)