Home Game Development unity – Character Controller reveals in scene however not in recreation

unity – Character Controller reveals in scene however not in recreation

0
unity – Character Controller reveals in scene however not in recreation

[ad_1]

When I press play my character controller turns black, the size on the z axis is 0 and all the kids will not be seen. Now the factor this solely occurs once I press play — if I do not, all the pieces is okay in my scene and recreation view.

Player (Parent object)
enter image description here

Player transfer script

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;

public class PlayerMove : MonoBehaviour
{
    public CharacterController controller;
    public float gravity = -30;
    public float sphereRadius = 0.2f;
    public Transform groundCheck;
    public LayerMask groundMask;
    public float jumpHeight = 3f;
    public float sprintSpeed = 20f;
    public float walkSpeed = 15f;
    public float crouchHeight = 0.5f;
    public float crouchSpeed;
    public float startHeight;

    personal Vector3 velocity;
    personal bool isGrounded = true;
    personal float pace;

    personal void Start() {
        velocity.y = 0f;
        pace = walkSpeed;
        crouchSpeed = pace / 2;
        startHeight = rework.localScale.y;
    }

    // Update known as as soon as per body
    personal void Update()
    {
        isGrounded = Physics.CheckSphere(groundCheck.place, sphereRadius, groundMask);

        float x = Input.GetAxisRaw("Horizontal");
        float z = Input.GetAxisRaw("Vertical");

        Vector3 transfer = rework.proper * x + rework.ahead * z;
        controller.Move(transfer.normalized * pace * Time.deltaTime);

        if (velocity.y < -0.35f)
        {
            velocity.y = -0.35f;
        }

        // Jumping and crouching
        if (Input.GetButtonDown("Jump") && isGrounded)
        {
            velocity.y = jumpHeight;
        } else if (Input.GetKey(KeyCode.LeftShift)) {
            pace -= 7.5f;
            rework.localScale = new Vector3(rework.localScale.x, crouchHeight, rework.localRotation.z);
        } else if (!Input.GetKey(KeyCode.LeftShift)) {
            pace = walkSpeed;
            rework.localScale = new Vector3(rework.localScale.x, startHeight, rework.localRotation.z);
        }

        // Sprinting
        if (Input.GetKey(KeyCode.LeftControl))
        {
            pace = sprintSpeed;
        }
        else if (!Input.GetKey(KeyCode.LeftControl))
        {
            pace = walkSpeed;
        }

        velocity.y += gravity * Time.deltaTime * Time.deltaTime;
        controller.Move(velocity);
    }
}

Player script

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;

public class Player : MonoBehaviour
{
    public float well being = 100f;

    public void TakeDamage(float quantity)
    {
        well being -= quantity;
        if (well being <= 0)
            Destroy(gameObject);
    }
}

Main Camera object
enter image description here

Camera look script

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;

public class CameraLook : MonoBehaviour
{
    public float sensitivity = 100f;
    public Transform playerBody;
    
    personal float xRotation;

    personal void Start() {
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.seen = false;
    }

    // Update known as as soon as per body
    void Update()
    {
        float mouseX = Input.GetAxis("Mouse X") * sensitivity * Time.fixedDeltaTime;
        float mouseY = Input.GetAxis("Mouse Y") * sensitivity * Time.fixedDeltaTime;

        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, -90f, 90f);

        rework.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
        playerBody.Rotate(Vector3.up * mouseX);
    }
}

Hierarchy
enter image description here

Here is a comparability for when i’m taking part in vs when not

not taking part in
not playing

taking part in
enter image description here

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here