Problem. Pick up and Grab object script, except all objects in scene are picked up instead of one.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PickUp : MonoBehaviour
{
public Transform theDest;
private bool hasPlayer = false;
private bool beingCarried = false;
private bool touched = false;
public Camera fpsCam;
RaycastHit hit;
void FixedUpdate()
{
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward , out hit, 5.5f))
{
hasPlayer = true;
}
else
{
hasPlayer = false;
}
if (hasPlayer && Input.GetMouseButton(1))
{
GetComponent<Rigidbody>().useGravity = false;
GetComponent<Rigidbody>().freezeRotation = true;
this.transform.position = theDest.position;
this.transform.parent = GameObject.Find("Destination").transform;
beingCarried = true;
}
else
{
this.transform.parent = null;
GetComponent<Rigidbody>().useGravity = true;
GetComponent<Rigidbody>().freezeRotation = false;
}
}
}
Hello, This is a script designed for pick up object with an FPS Camera. This script is applied to each object I would like to pick up. The problem is, when i pick up one object with the script, they all transform to the one I'm holding. I also cant differentiate with separate tags because this needs to be implemented on a large scale and procedural. Any help would be much appreciated. Thanks.
Comment
Your answer
Follow this Question
Related Questions
Ray cast to object to transform, instead all objects with script transform. 0 Answers
Raycast only occurs on start 2 Answers
Bugging ragdoll 1 Answer
How to Make A Character Stop At Wall? 0 Answers
How to apply a force at certain point of an object? 0 Answers