I recently got a script that’s supposed to make the player align with the camera when the player moves. The problem is I have a parsing error that I’m having trouble fixing. Here’s my script
using UnityEngine;
using System.Collections;
public class CharacterAlign1 : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
//Return direction align with Camera
Vector3 targetDirection
{
get
{
Vector3 cameraForward = mainCamera.TransformDirection(Vector3.forward);
cameraForward.y = 0; //set to 0 because of camera rotation on the X axis
//get the right-facing direction of the camera
Vector3 cameraRight = mainCamera.TransformDirection(Vector3.right);
//determine the direction the player will face based on input and the camera's right and forward directions
return Input.GetAxis("Horizontal") * cameraRight + Input.GetAxis("Vertical") * cameraForward;
}
}
//This method needs to run on Update
void RotateWhileMoving()
{
if(speed > 0.5f)
{
//normalize the direction the player should face
Vector3 lookDirection = targetDirection.normalized;
//rotate the player to face the correct direction ONLY if there is any player input
if (lookDirection != Vector3.zero)
{
newRotation = Quaternion.LookRotation(lookDirection);
transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, 4.5f * Time.deltaTime);
}
}
}
How do I fix it. It’s on line (18,1). I know I already asked about this n another thread, but this is a way less confusing one. Thanks!