Question by
sa3fi · Jan 13, 2020 at 09:38 AM ·
movementscript.movement script
I keep getting "Behavior (Game Object 'Player') is missing" and "Behavior is missing!"
I keep getting this error and i can't move is something wrong with the script ?
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class PlayerController : MonoBehaviour
{
public float speed = 6f;
public float gravity = 20f;
public float jump = 8;
CharacterController controller;
Animator anim;
public float rotSpeed = 80f;
float rot = 0f;
float horizontal;
float vertical;
Vector3 moveDirection = Vector3.zero;
// Use this for initialization
void Start () {
controller = GetComponent<CharacterController>();
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update ()
{
horizontal = Input.GetAxis("Horizontal");
vertical = Input.GetAxis("Vertical");
if (controller.isGrounded)
{
moveDirection = new Vector3(0,0.0f, vertical);
moveDirection *= speed;
moveDirection = transform.TransformDirection(moveDirection);
if (Input.GetButton("jump"))
{
anim.SetBool ("isJumping", true);
moveDirection.y = jump;
}
else{
anim.SetBool("isJumping",false);
}
if(Input.GetKey(KeyCode.Z))
{
anim.SetBool("isWalking",true);
}
else
{
anim.SetBool("isWalking",false);
}
}
rot += Input.GetAxis("Horizontal") * rotSpeed * Time.deltaTime;
transform.eulerAngles = new Vector3(0, rot, 0);
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}
,I keep getting this error for this script is something wrong with the script ?
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class PlayerController : MonoBehaviour
{
public float speed = 6f;
public float gravity = 20f;
public float jump = 8;
CharacterController controller;
Animator anim;
public float rotSpeed = 80f;
float rot = 0f;
float horizontal;
float vertical;
Vector3 moveDirection = Vector3.zero;
// Use this for initialization
void Start () {
controller = GetComponent<CharacterController>();
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update ()
{
horizontal = Input.GetAxis("Horizontal");
vertical = Input.GetAxis("Vertical");
if (controller.isGrounded)
{
moveDirection = new Vector3(0,0.0f, vertical);
moveDirection *= speed;
moveDirection = transform.TransformDirection(moveDirection);
if (Input.GetButton("jump"))
{
anim.SetBool ("isJumping", true);
moveDirection.y = jump;
}
else{
anim.SetBool("isJumping",false);
}
if(Input.GetKey(KeyCode.Z))
{
anim.SetBool("isWalking",true);
}
else
{
anim.SetBool("isWalking",false);
}
}
rot += Input.GetAxis("Horizontal") * rotSpeed * Time.deltaTime;
transform.eulerAngles = new Vector3(0, rot, 0);
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612221417im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
RogueLike 2D (Tutorial) Rotation of Player 1 Answer
1st Person shooter, move player forward where cam is facing 1 Answer
Help with jumping script 2 Answers
Movement scrip 0 Answers
Stop movement on collision 1 Answer