Freezing scale of the player
Hello everyone,
Since I've been doing some research for my game and making different system, I'm actually scratching my head off on something who seems sooooo easy... well i'm making a "ant-man" system where the player is being reduced by 5 is scale when you hit the "f" button. But it keeps being reduced when you hit a second time "f". I would like not you know haha, just like a jumping system. I konw it will be a simple answer but you know that kind of stuff making you crazyyy.. here the script guys and thanks for your time. peeeace.
using UnityEngine;
using System.Collections;
public class changeOnButton : MonoBehaviour {
bool timing = false;
float time = 5.0f;
// Update is called once per frame
void Update () {
if (Input.GetKeyDown("f"))
{
transform.localScale = new Vector3(transform.localScale.x / 5, transform.localScale.y / 5, transform.localScale.z / 5);
timing = true;
}
if(timing)
{
time -= Time.deltaTime;
if(time <= 0)
{
transform.localScale = new Vector3(transform.localScale.x * 5, transform.localScale.y * 5, transform.localScale.z * 5);
timing = false;
time = 5.0f;
}
}
}
}
Answer by OncaLupe · Nov 08, 2015 at 09:16 PM
You just need to add a boolean to show if it's been used or not. Something like this:
bool used = false;
void Update () {
if (Input.GetKeyDown("f") && !used)
{
used = true;
//do stuff
}
}
Your answer
Follow this Question
Related Questions
Spawn player and scale 0 Answers
Change player scale based on location on Y Axis. 0 Answers
trouble switching between booleans 2 Answers
Problem with player scale 0 Answers
Scaling material without saving scale on original material 1 Answer