- Home /
Duplicate Question - http://docs.unity3d.com/Manual/ControllingGameObjectsComponents.html
How to change public variable by another script
I'm using Character Controller which sets speed of player. I want to create a script which can stop character after pressing C by setting speed to 0 and set animation named "Sit". After pressing C again, character returns to default animation (standing) and is able to walk. The problem is that I don't know how to change public speed variables from Character Controller using my script and how to set animation that will be active until I press C again.
That's the way I wanted to this.
pressing C
set animation "Sits"
stop by setting speed to 0 (or in another way)
pressing C
set animation returns to default
set speed to default - character is able to moving
using UnityEngine; using System.Collections; public class OtherMovements : MonoBehaviour { bool isSitting = false; // Update is called once per frame void Update () { if (Input.GetMouseButton(0)) { animation.Play("Attack"); } if (Input.GetKey (KeyCode.C) && isSitting == false) { isSitting = true; transform.animation.Play("Sits"); } if (Input.GetKey (KeyCode.C) && isSitting == true) { isSitting = false; transform.animation.Play("Walk"); } } }
Follow this Question
Related Questions
How to link this 2 variables from 2 different scripts / gameobjects? 1 Answer
How to access scripts other than by name. 1 Answer
How to get a ONLY the INSPECTOR variables that can be modified. 0 Answers
Changing the shoot angle on one robot changes all of the other robots' variables? 1 Answer
Adding variables from all scripts 2 Answers