Hi, I am trying to write a small script for crouching. As my character crouches I want it to slow down. The problem I have is that after I declared this:
characterController = gameObject.GetComponent();
controller = gameObject.GetComponent();
I am not able to use them together. Both statements above won;t work together and my quetion is. What am I missing?
Cheers!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
public class Crouch : MonoBehaviour
{
CharacterController characterController;
FirstPersonController controller;
// Use this for initialization
void Start()
{
characterController = gameObject.GetComponent<CharacterController>();
controller = gameObject.GetComponent<FirstPersonController>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.LeftControl))
{
characterController.height = 1.0f;
controller.m_WalkSpeed = 2;
}
else
controller.m_WalkSpeed = 5;
characterController.height = 1.8f;
}
}