using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.ThirdPerson;
public class Flashlight : MonoBehaviour {
public GameObject playerToAttach;
// Use this for initialization
void Start ()
{
var someBone = playerToAttach.transform.Find("LeftShoulder/Arm/Hand");
transform.parent = someBone;
transform.localPosition = someBone.position;
transform.localRotation = someBone.localRotation;
transform.localScale = someBone.localScale;
}
// Update is called once per frame
void Update () {
}
}
I attach the script to a cube. I want to attach the cube to the ThirdPersonController hand. So i dragged the ThirdPersonController to the inspector to the script in the cube.
But the variable someBone is null all the time. playerToAttach is not null.
I guess doing: Find(“LeftShoulder/Arm/Hand”); is wrong way.
Also the rest of the code is wrong i guess:
transform.localPosition = someBone.position;
transform.localRotation = someBone.localRotation;
transform.localScale = someBone.localScale;
What i want to do is to attach an object to the thirdpersoncontroller hand. Like he is holding the object.