Crouching
If i press C, i want the CharacterController’s height rezise to half of its original. How?
Crouching
If i press C, i want the CharacterController’s height rezise to half of its original. How?
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
public GameObject goCharacterControllerGraphics;
public float defaultHeight;
// Use this for initialization
void Start ()
{
goCharacterControllerGraphics = GameObject.FindWithTag("Player").transform.FindChild("Graphics").gameObject;
defaultHeight = goCharacterControllerGraphics.transform.localScale.y;
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyUp(KeyCode.C))
{
if (goCharacterControllerGraphics.transform.localScale.y == defaultHeight)
{
goCharacterControllerGraphics.transform.localScale = new Vector3(goCharacterControllerGraphics.transform.localScale.x, 0.5f * defaultHeight, goCharacterControllerGraphics.transform.localScale.z);
}
else
{
goCharacterControllerGraphics.transform.localScale = new Vector3(goCharacterControllerGraphics.transform.localScale.x, defaultHeight, goCharacterControllerGraphics.transform.localScale.z);
}
}
}
}