When a key is pressed, I want my bone to rotate. Here is my code so far:
using UnityEngine;
using System.Collections;
public class myAction : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.A)){
GetComponent<Animation>().Play("animation1");
}
}
void LateUpdate(){
if (Input.GetKeyDown (KeyCode.B)) {
(GetComponent<Transform>().Find("RootBone/Bone3")).eulerAngles = new Vector3 (0, 0, 90);
}
}
}
After Edit, I get the following error:
NullReferenceException: Object reference not set to an instance of an object
rotateBones.LateUpdate () (at Assets/rotateBones.cs:20)
Try it like this:
using UnityEngine;
using System.Collections;
public class myAction : MonoBehaviour {
public Transform bone;
// Use this for initialization
void Start () {
bone = GetComponent<Transform>().Find("RootBone/Bone3");
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.A)){
GetComponent<Animation>().Play("animation1");
}
}
void LateUpdate(){
if (Input.GetKeyDown (KeyCode.B)) {
if(bone != null) {
bone.eulerAngles = new Vector3 (0, 0, 90);
}
else {
Debug.Log("bone is null!");
}
}
}
}
I use script to animate Bone, I use character created with MAKEHUMAN software, i mean to rotate a bone to 90 degrees, the bone rotated well but not animated, the bone rotated instantly so we can’t see the rotating progress, i want this bone rotate process finish after 3 second, how to make that happen, this is my current code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BoneAccess : MonoBehaviour
{
public Transform bone;
// Start is called before the first frame update
void Start()
{
bone = GetComponent<Transform>().Find("MakeHuman default skeleton/root/spine05/spine04");
}
// Update is called once per frame
void Update()
{
if(bone != null) {
bone.localEulerAngles = new Vector3 (130, 0, 0);
}
else {
Debug.Log("bone is null!");
}
}
}