so, I wanted my player to stop movement and play idle animation when dialouge enables PLEASE HELP I am stuck
PLAYER SCRIPT
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PLAYER : MonoBehaviour
{
//private SpriteRenderer _renderer;
public ParticleSystem dust;
public float speed;
public float jump;
public float move;
public bool jumping;
[SerializeField] AudioSource airsoundeffect;
[SerializeField] AudioSource runsoundeffect;
[SerializeField] AudioSource jumpsoundeffect;
public Animator anim;
bool facingRight = true;
private shake shake;
public bool canmove;
public Rigidbody2D rb;
void Start() {
rb = GetComponent<Rigidbody2D>();
anim = GetComponentInParent<Animator>();
shake = GameObject.FindGameObjectWithTag("screenshake").GetComponent<shake>();
Findstartpos();
canmove = false;
}
void Awake()
{
DontDestroyOnLoad(this.gameObject);
}
void Update() {
if(canmove = true){
move = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(speed * move, rb.velocity.y);
}
if (Input.GetButtonDown("Jump") && jumping == false)
{
CreateDust();
rb.AddForce(new Vector2(rb.velocity.x, jump));
}
if(jumping == false){
anim.SetBool("isjumping", false);
}
if(jumping == true){
runsoundeffect.Stop();
anim.SetBool("isjumping", true);
}
if(canmove = true){
if(move >= 0.1f || move <= -0.1f)
{
CreateDust();
anim.SetBool("isrunning", true);
}
if(canmove = false){
anim.SetBool("isrunnig", false);
}
}
else{
anim.SetBool("isrunning", false);
}
if(move >= 0.1f || move <= -0.1f){
if(!runsoundeffect.isPlaying)
runsoundeffect.Play();
}
else
runsoundeffect.Stop();
if(move< 0 && facingRight)
{
Flip();
}
else if (move> 0 && !facingRight)
{
Flip();
}
}
private void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.CompareTag("Floor"))
{
if(!jumpsoundeffect.isPlaying)
jumpsoundeffect.Play();
CreateDust();
jumping = false;
shake.camshake();
}
else
jumpsoundeffect.Stop();
}
private void OnCollisionExit2D(Collision2D other) {
if (other.gameObject.CompareTag("Floor"))
{
CreateDust();
jumping = true;
if(!airsoundeffect.isPlaying)
airsoundeffect.Play();
}
else
airsoundeffect.Stop();
}
void Flip()
{
CreateDust();
Vector3 currentScale = gameObject.transform.localScale;
currentScale.x *= -1;
gameObject.transform.localScale = currentScale;
facingRight = !facingRight;
}
void CreateDust(){
dust.Play();
}
private void OnLevelwasLoaded(int level)
{
Findstartpos();
}
void Findstartpos(){
transform.position = GameObject.FindWithTag("startpos").transform.position;
}
}
AND THIS IS IMPORTANT CONVERSATION MANAGER SCRIPT
public void StartConversation(NPCConversation conversation)
{
m_conversation = conversation.Deserialize();
if (OnConversationStarted != null)
OnConversationStarted.Invoke();
playerscript.speed = 0f;
playerscript.canmove = false;
TurnOnUI();
m_currentSpeech = m_conversation.Root;
SetState(eState.TransitioningDialogueBoxOn);
}
public void EndConversation()
{
SetState(eState.TransitioningDialogueOff);
if (OnConversationEnded != null)
OnConversationEnded.Invoke();
playerscript.speed = 16f;
playerscript.canmove = true;
}