-Then- statement for scipts.
Hi,
in my script I want to have a statement that if a float is 1 and gets smaller in the next seconds something happens but I don't know how to write this. I would need something like a "then" statement. In my case I want to activate a animation per bool if the float "speed" is 1 and shrinks. If the speed is at its minimum 0 the boul turns false. It may sounds a bit confusing but I would describe what I want to do like this.
Answer by Fewpwew130 · Sep 17, 2015 at 03:51 PM
Hi, maybe something like this:
public float variableone;
public Animator anim;
void Update(){
if (variableone == 1f){
anim.SetBool("Speed", (bool));
}
}
Don't know if the code is right, though.
I don't think it is exactly what I need. I will explain more detailed what I want to do without uploading my whole 100 lines script. If my Player has the speed of 1 (his full speed) he runs as normally but as he turns and his speed isn't anymore 1 he slides (by activating a bool). But as well he has a speed of 0 this bool is false. That's why I need a kind of "then". This is what I imagined it could be like:
if ($$anonymous$$athf.Abs(Input.GetAxis("Horizontal")) = 1)
{
then
{
if ($$anonymous$$athf.Abs(Input.GetAxis("Horizontal")) > 1)
{
sliding = true;
}
}
}
if ($$anonymous$$athf.Abs(Input.GetAxis("Horizontal")) = 0)
{
sliding = false;
}
bool sliding;
bool canSlide;
void Update () {
if ($$anonymous$$athf.Abs (Input.GetAxis ("Horizontal")) == 1) {
Debug.Log ("Do Something");
canSlide = true;
}
if ($$anonymous$$athf.Abs (Input.GetAxis ("Horizontal")) < 0.9f && $$anonymous$$athf.Abs (Input.GetAxis ("Horizontal")) > 0.1f && canSlide) {
sliding = true;
Debug.Log (sliding);
}
if ($$anonymous$$athf.Abs (Input.GetAxis ("Horizontal")) == 0) {
sliding = false;
canSlide = false;
Debug.Log (sliding);
}
}
At first thanks for you reply. It is nearly what I want. The only difference is that the player first has to reach the speed of 1 and then if the speed drops the sliding gets true. I put this part of you script in my script but sliding gets also activated if the speed of 1 was never reached yet.
Your answer
Follow this Question
Related Questions
Getting attack to go back to false? 0 Answers
2D Spine Animation not playing 0 Answers
Import animation from Adobe Animate(JSON) 1 Answer
Professional shortcuts/functions for Animators in the Unity 0 Answers
Create Idle/Walk/Run Blendtree 1 Answer