Whenever I try clicking on an object on the scene, Can’t select objects
Attach code & link to FBX file
function Update()
{
if(Input.GetMouseButtonDown(0))
{
mouspos=Input.mousePosition;
if( Physics.Raycast(camera.ScreenPointToRay(mouspos), hitt, 100 ) || Physics.Raycast(camera.allCameras[1].ScreenPointToRay(mouspos), hitt, 100 ) ) {
if( hitt.rigidbody && hitt.rigidbody.isKinematic ) {
gam = hitt.rigidbody.gameObject;
gam.transform.position.x += 0.001;
}
}
}
}
This script moves the object clicked 1 milimeter per frame in the X axis direction. The object must be kinematic, and it will stop moving when the mouse pointer isn’t over it anymore. Is it what you’re trying to do?
There’s a problem in this code: if you have two cameras, both will cast rays to the scene. With two rays, two different objects may be hit - but in your code only the object hit by the second camera will be moved. Since you use the same hitt variable in both raycasts, the second result overwrites the first one (actually, it depends on how the compiler assembles this code).
You can avoid this by checking the second camera only if the first one hit nothing, like this:
...
var hitFlag = Physics.Raycast(camera.ScreenPointToRay(mouspos), hitt, 100 );
if (!hitFlag) hitFlag = Physics.Raycast(camera.allCameras[1].ScreenPointToRay(mouspos), hitt, 100 );
if (hitFlag && hitt.rigidbody && hitt.rigidbody.isKinematic ) {
gam = hitt.rigidbody.gameObject;
gam.transform.position.x += 0.001;
}
...
still it doesn’t
i attach my project can any one solve this problem