Im trying to make gameObject move only if specific button is pressed
Like I said, Im trying to make gameObject move only if specific button is pressed, now the object moves every time i press a button that plays sound. I would like it to move only if specific button is pressed or specific sound is playing. I would really appreciate any help :)
Here is my script:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class StopButtonRotation : MonoBehaviour { public Rigidbody2D rigidBody2D; public GameObject button;
void Start()
{
rigidBody2D = GetComponent<Rigidbody2D>();
rigidBody2D.rotation = -90f;
}
void FixedUpdate()
{
if (button.tag.Equals("Button2"))
{
if (Playsound.isPlaying)
{
if (rigidBody2D.rotation <= 0f)
{
rigidBody2D.rotation += 4.0f;
}
else
{
rigidBody2D.rotation += 0.0f;
}
}
else
{
rigidBody2D.rotation = -90f;
}
}
else
{
rigidBody2D.rotation = -90f;
}
}
}
I think the problem is with this line:
if (button.tag.Equals("Button2"))
Answer by alussam · Jan 02, 2019 at 11:31 AM
Start from here: https://answers.unity.com/questions/1405351/moving-player-leftright-with-buttons.html https://forum.unity.com/threads/using-a-button-to-move-an-object.291758/
Your answer
Follow this Question
Related Questions
How can I generate and setup buttons via code 1 Answer
Help with rotation please 2 Answers
Button bool doesn´t work correctly weird 1 Answer
how do i say this 1 Answer
Unity Update is ignoring the GetKey part of my statement!? 2 Answers