I’m using Raycasting to pickup a weapon on button click. When I do the weapon is parented to the RightHand bone but when I move the weapon doesn’t move with me. Not sure what I’m doing wrong.
using UnityEngine;
using System.Collections;
using NN.UMAScripts;
public class HoldWeapons : MonoBehaviour {
public GameObject weaponToHold;
public GameObject hand;
public GameObject body;
// Use this for initialization
void Start () {
hand = GameObject.Find("RightHand");
body = GameObject.Find("MyPlayer");
}
// Update is called once per frame
void Update () {
PickupWeapon();
}
void PickupWeapon()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
Debug.DrawRay(ray.origin, ray.direction * 10, Color.red);
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast(ray, out hit) == true&&hit.collider.tag=="Pickup.Weapon")
{
weaponToHold = hit.collider.gameObject;
weaponToHold.transform.parent = hand.transform;
weaponToHold.transform.localPosition = new Vector3(0, 0, 0);
weaponToHold.transform.rotation = new Quaternion();
Debug.Log(weaponToHold.name);
}
}
}
}