Idk how to explain, i made a button that pauses the game (left top corner) its working good but the problem is that when i touch that button, my player object also gets the touch input for his script(it
s jumping)
Here is my player script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Player : MonoBehaviour
{
public Rigidbody2D rb;
public int health=1;
public GameObject gameOver;
public Animator anim;
void Start()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
void Update()
{
if (health <= 0)
{
gameOver.SetActive(true);
Destroy(gameObject);
}
if (health == 1)
{
anim.Play("Player1");
}
else if (health==2)
{
anim.Play("Player_shield");
}
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began || Input.GetMouseButton(0))
{
anim.SetFloat("runMultiplier", 1f);
rb.velocity = new Vector2(rb.velocity.x, 7);
rb.velocity = new Vector2(rb.velocity.x, 7);
}
else
{
anim.SetFloat("runMultiplier", 0.7f);
}
}
}
and here is my pause button script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class PauseButton : MonoBehaviour
{
public GameObject PauseMenuUI;
public void Pause()
{
PauseMenuUI.SetActive(true);
Time.timeScale = 0f;
}
}
So when i press the pause button, the player also jumps and when i exit the pause menu it is going up(continues the movement input), i thought about disabling the update function on player whenever i press the pause button, but i dont know how and not sure if it
ll work. Can you give me some tips?
Thank you!