Dear Community,
I am another newcomer to Unity3d and C#. I have created a scene in order to grasp the concept of classes and instances. In the scene a player (capsule) stands in front of a bank (lots of cubes) next to his car(another cube). (see here)
As you can see the Player Controller has a “Character Controller” Component attached and a “Client Controller” Script, which goes like this:
using UnityEngine;
using System.Collections;
public class ClientController : MonoBehaviour {
public float speed = 4.0f;
public float jumpSpeed = 7.0f;
public float gravity = 30.0f;
Vector3 direction = Vector3.zero;
CharacterController controller;
void Start ()
{
controller = GetComponent<CharacterController> ();
}
void FixedUpdate ()
{
Move ();
}
void Move ()
{
if (controller.isGrounded)
{
direction = new Vector3 (Input.GetAxis ("Horizontal"), 0f, Input.GetAxis ("Vertical"));
direction *= speed;
if (Input.GetButton ("Jump"))
{
direction.y = jumpSpeed;
}
}
direction.y -= gravity * Time.deltaTime;
controller.Move(direction*Time.deltaTime);
}
}
My problem is, that as soon as I switch to Game mode my Player GameObject moves out of the camera view, to a weird position somewhere, where no man has gone before (see here)
I don’t know why?? This does not happen if I deactivate the Client Controller Script or my “character Controller” component or both.
The error occurred after I altered my “police” prefab, that is instantiated when the player enters the bank not using the door (or metal detector).
Can anyone help me? Thank you!