I am working through the “Stealth” tutorial and have come to a stop because I can not solve this code problem. Can someone please help me solve this error message.
Here is the error list:
- Assets/scripts/Player/PlayerMovement.cs(55,78): error CS0103: The name `targetRotation’ does not exist in the current context
- Assets/scripts/Player/PlayerMovement.cs(55,53): error CS1502: The best overloaded method match for `UnityEngine.Quaternion.Lerp(UnityEngine.Quaternion, UnityEngine.Quaternion, float)’ has some invalid arguments
- Assets/scripts/Player/PlayerMovement.cs(55,53): error CS1503: Argument
#2' cannot convert
object’ expression to type `UnityEngine.Quaternion’
Here is the code:
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour
{
public AudioClip shoutingClip;
public float turnSmoothing = 15f;
public float speedDampTime = 0.1f;
private Animator anim;
private HashIDs hash;
void Awake()
{
anim = GetComponent<Animator>();
hash = GameObject.FindGameObjectWithTag(Tags.gameController).GetComponent<HashIDs>();
anim.SetLayerWeight(1,1f);
}
void FixedUpdate()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
bool sneak = Input.GetButton("Sneak");
MovementManagement(h, v, sneak);
}
void Update()
{
bool shout = Input.GetButtonDown ("Attrack");
anim.SetBool(hash.shoutingBool, shout);
AudioManagment(shout);
}
void MovementManagement(float horizontal, float vertical, bool sneaking)
{
anim.SetBool(hash.sneakingBool, sneaking);
if(horizontal != 0f || vertical != 0f)
{
Rotating(horizontal, vertical);
anim.SetFloat(hash.speedFloat, 5.5f, speedDampTime, Time.deltaTime);
}
else
{
anim.SetFloat (hash.speedFloat, 0f);
}
}
void Rotating(float horizontal, float vertical)
{
Vector3 TargetDirection = new Vector3(horizontal, 0f, vertical);
Quaternion targetDirection = Quaternion.LookRotation(TargetDirection, Vector3.up);
Quaternion newRotation = Quaternion.Lerp(rigidbody.rotation, targetRotation, turnSmoothing * Time.deltaTime);
rigidbody.MoveRotation(newRotation);
}
void AudioManagment(bool shout)
{
if(anim.GetCurrentAnimatorStateInfo(0).nameHash == hash.locomotionState)
{
if(!audio.isPlaying)
{
audio.Play ();
}
}
else
{
audio.Stop();
}
if(shout)
{
AudioSource.PlayClipAtPoint(shoutingClip, transform.position);
}
}
}