I'm not sure what I am doing wrong, but it seems only the last object placed is working properly.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Raycastpickup : MonoBehaviour {
public float distance = 10f;
public float floatDistance = 1f;
public Rigidbody IK;
// Use this for initialization
void Start () {
IK = GameObject.FindWithTag("GrabbableObject").GetComponent();
}
void Carry(GameObject pickUp)
{
}
RaycastHit hit;
// Update is called once per frame
void Update(){
Vector3 forward = transform.TransformDirection(Vector3.forward) * distance;
Debug.DrawRay(transform.position, (forward), Color.red);
if (Physics.Raycast(transform.position, (forward), out hit, distance))
{
if (hit.collider.CompareTag("GrabbableObject") && Input.GetButtonDown("E") == true)
{
hit.transform.parent = GameObject.FindGameObjectWithTag("Arm").transform;
IK.isKinematic = true;
}
if (!hit.collider.CompareTag("GrabbableObject") || Input.GetButtonUp("E") == true)
{
IK.isKinematic = false;
GameObject.FindGameObjectWithTag("GrabbableObject").transform.SetParent(null);
}
}
}
}
I've been messing around with it for a few hours and I can't seem to make a system where when I grab an object with my RayCastHit at a certain distance it moves it. Any help would be much appreciated and please know I am fairly new. I've tried multiple ways of trying to set up the parent to drop the first grabbable object, but it refuses to drop and stays stuck with no Is Kinematic applied. Thanks ahead of time!
↧