Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Crouch script not working

Discussion in 'Scripting' started by Gigget, May 21, 2020.

  1. Gigget

    Gigget

    Joined:
    May 20, 2020
    Posts:
    9
    Watched a tutorial on crouch script I don't know we its not working heres the script

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class crouch : MonoBehaviour
    {
    CharacterController characterCollider;
    // Start is called before the first frame update
    void Start()
    {
    characterCollider = gameObject.GetComponent<CharacterController> ();
    }
    // Update is called once per frame
    void Update()
    {
    if (Input.GetKey(KeyCode.LeftControl) ) {
    characterCollider.height = 1.0f;
    }
    else
    {
    characterCollider.height = 3.8f;
    }
    }
    }
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
  3. Gigget

    Gigget

    Joined:
    May 20, 2020
    Posts:
    9
    its doing nothing I want it to move the camera down
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    Hmmm, well how do they move the camera down in the tutorial you watched? Did you follow their steps exactly?
     
  5. Gigget

    Gigget

    Joined:
    May 20, 2020
    Posts:
    9
    the tutorial I copied exactly and in the video the capsule moved and so did the camera
     
  6. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    So I found your tutorial (I think). It's important to note that this tutorial starts with the Standard Asset FPSController asset. Are you using that asset?

     
  7. Gigget

    Gigget

    Joined:
    May 20, 2020
    Posts:
    9
    that's the tutorial I did not sea the it used the asset
     
  8. Gigget

    Gigget

    Joined:
    May 20, 2020
    Posts:
    9
    nevermind I made tweeks to the code and now I can crouch
     
  9. Gigget

    Gigget

    Joined:
    May 20, 2020
    Posts:
    9
    but now sometimes it goes threw the floor