I wan to make the charcter in slow motion if slow function is activated
//////////////////////////////////////////////////
using UnityEngine;
using System.Collections;
// Require a character controller to be attached to the same game object
[RequireComponent(typeof (CharacterController))]
[AddComponentMenu(“Third Person Player/Third Person Controller”)]
public class Gravity : MonoBehaviour {
public float rotationDamping = 20.0f;
public float runSpeed = 10.0f;
public float fallinggravity = 9.8f;
public float jumpSpeed = 8.0f;
public float risinggravity = 15f;
bool slow = false;
bool freeze=false;
bool fastforward=false;
bool canJump;
float moveSpeed;
float verticalVel; // Used for continuing momentum while in air
CharacterController controller;
//public Vector3 moveDirection = Vector3.zero;
void Start()
{
moveSpeed = runSpeed;
controller = (CharacterController)GetComponent(typeof(CharacterController));
}
float UpdateMovement()
{
// Movement
float x = Input.GetAxis(“Vertical”);
float z = Input.GetAxis(“Horizontal”);
Vector3 inputVec = new Vector3(x, 0, z);
inputVec *= runSpeed;
controller.Move((inputVec + Vector3.up * -risinggravity + new Vector3(0, verticalVel, 0)) * Time.deltaTime);
// Rotation
// if (inputVec != Vector3.zero)
// transform.rotation = Quaternion.Slerp(transform.rotation,Quaternion.LookRotation(inputVec),
// Time.deltaTime * rotationDamping);
return inputVec.magnitude;
}
void Update()
{
// Check for jump
if (controller.isGrounded )
{
canJump = true;
if ( canJump Input.GetKeyDown(“space”) )
{
// Apply the current movement to launch velocity
verticalVel = jumpSpeed;
canJump = false;
}
}else
{
// Apply gravity to our velocity to diminish it over time
verticalVel -= fallinggravity * Time.deltaTime;
if(runSpeed > 0)
runSpeed += (runSpeed + jumpSpeed)/fallinggravity * Time.deltaTime;
}
//check for freeze
if(freeze)
{
moveSpeed=0;
}
//check for slow
if (slow)
{
moveSpeed =10.0f;
jumpSpeed = 40.0f;
}
if (fastforward)
{
moveSpeed =50.0f;
jumpSpeed = 70.0f;
}
// Actually move the character
UpdateMovement();
if ( controller.isGrounded )
{
verticalVel = 0f;// Remove any persistent velocity after landing
runSpeed = moveSpeed;
}
}
}