Hey all, I know this question pops up a lot, but I'm fairly new to Unity and my issue is a bit odd. I've been following the animation section of the stealth tutorial for use for my own project. The Animation controller itself is set up properly, but I'm getting errors in the script for some reason. Here's the code:
using UnityEngine;
using System.Collections;
public class EdelController : MonoBehaviour
{
public int locomotionState;
public int speedFloat;
public float turnSmoothing = 15f;
public float speedDampTime = 0.1f;
void Awake ()
{
locomotionState = Animator.StringToHash("Base Layer.Locomotion");
speedFloat = Animator.StringToHash("Speed");
Animator = GetComponent();
Animator.SetLayerWeight(1, 1f);
}
void FixedUpdate ()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
MovementManagement(h, v);
}
void MovementManagement(float horizontal, float vertical)
{
if (horizontal != 0f || vertical != 0f)
{
Rotating(horizontal, vertical);
Animator.SetFloat(speedFloat, 5.5f, speedDampTime, Time.deltaTime);
}
else
{
Animator.SetFloat(speedFloat, 0f);
}
}
void Rotating(float horizontal, float vertical)
{
Vector3 targetDirection = new Vector3(horizontal, 0f, vertical);
Quaternion targetRotation = Quaternion.LookRotation(targetDirection, Vector3.up);
Quaternion newRotation = Quaternion.Lerp(rigidbody.rotation, targetRotation, turnSmoothing * Time.deltaTime);
rigidbody.MoveRotation(newRotation);
}
}
According to the errors such as:
Assets/Scripts/EdelController.cs(18,26): error CS0120: An object reference is required to access non-static member `UnityEngine.Animator.SetLayerWeight(int, float)'
Assets/Scripts/EdelController.cs(82,34): error CS0120: An object reference is required to access non-static member `UnityEngine.Animator.SetFloat(string, float)'
Assets/Scripts/EdelController.cs(86,34): error CS0120: An object reference is required to access non-static member `UnityEngine.Animator.SetFloat(string, float)'
The Culprit is in the MovementManagement function.
please help..
↧