I am making a game where your only goal is to cause havoc. Right now I have a script where I am able to pick up and move around objects. The only problem is that I pick up all the objects instead of just one.
`var other : Rigidbody;
function Update () {
if(Input.GetButtonDown(“Fire1”)) {
other.transform.parent = transform;
}else if(Input.GetButtonUp("Fire1")) {
other.transform.parent = null;
}
}
`
If you are picking up objects i would use a RayCast Then within your update method i would do something like
if (Physics.Raycast (transform.position, Vector3.forward, hit, 100.0))`
{
if(hit.collider.gameObject.tag == "PickUpableObject")
{
hit.transform.parent = transform;
}
else
{
hit.transform.parent = null;
}
}
This way only what ever the ray hit will be picked up.
The code is on the Main Camera. I tried using a RayCast but I kept getting errors like “Assets/Script/PickUpObject.js(5,25): BCE0023: No appropriate version of ‘UnityEngine.Physics.Raycast’ for the argument list ‘(UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.Rigidbody, float)’ was found.” I havent tried a GetComponent and I’m not sure how I would exactly do that.