Question by
IKilledKenny_2 · Apr 18, 2016 at 03:20 PM ·
collisionmovementcharacterpause game
How do i pause everything around me but i can still move my character
Hello Unity3D.I have a question about pausing?How can i make it that when i press a button my character pauses everything around him/her but i still able to play other animations or be able to control the character that paused everything around with?For example.If i press the "shift key" all the enemies stop movement and but i still have control of my character.If anyone knows how i can do this?Can you please tell me how?
Comment
you can make a public bool & cheek from each object scripts that should stop if it true then stop & offcurce it will only get true if you press the "shift key"
Is there a way to make script var arrays?For example?I want to cancel 3 scripts at once using variables by pressing the shift key.Is there a way to do so?
Best Answer
Answer by TBruce · Apr 18, 2016 at 11:25 PM
Add the script below to all enemies or merge it in with your current enemy script
using UnityEngine;
using System.Collections;
public class Enemy : MonoBehaviour
{
PlayerScript player = null;
Collider collider = null;
void Start()
{
collider = gameObject.GetComponent<Collider>();
if (collider == null)
{
Debug.LogWarning("A Collider component is missing. Please add one.");
}
// first find the player GameObject
GameObject go = GameObject.FindGameObjectsWithTag("Player");
if (go != null)
{
player = go.GetComponent<PlayerScript>();
if (player == null)
{
Debug.LogWarning("PlayerScript component missing from the player gameobject. Please add one.");
}
}
else
{
Debug.LogWarning("Could not find a GameObject tagged \"Player\". Please tag the player GameObject as \"Player\".");
}
}
void Update()
{
if ((player != null) && (collider != null) &&
(Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift)))
{
collider.enabled = false;
}
else
{
collider.enabled = true;
}
}
}