using System.Collections; using System.Collections.Generic; using UnityEngine; public class MoveTombstone : MonoBehaviour { public string position; public float x; public float y; public Vector3 temp; public string tombstone; public string goal; public float speed = 3f; public string pos; Animator m_Animator; public string m_ClipName; AnimatorClipInfo[] m_CurrentClipInfo; public GameObject player; // Start is called before the first frame update void Start() { speed = 100f; x = transform.position.x; y = transform.position.y; position = PlayerPrefs.GetString(tombstone); if(position == "top") { temp.x = x; temp.y = y + 1; goal = "set"; pos = "top"; } else if (position == "bottom") { temp.x = x; temp.y = y - 1; goal = "set"; pos = "bottom"; } else if (position == "right") { temp.x = x + 1; temp.y = y; goal = "set"; pos = "right"; } else if (position == "left") { temp.y = y; temp.x = x - 1; goal = "set"; pos = "left"; } if (x == transform.position.x && y == transform.position.y) { PlayerPrefs.SetString(tombstone, "start"); } player = GameObject.FindWithTag("Player"); speed = 3f; } // Update is called once per frame void Update() { position = PlayerPrefs.GetString(tombstone); if (goal == "set") { transform.position = Vector3.MoveTowards(transform.position, temp, speed * Time.deltaTime); } if(transform.position == temp) { goal = "nothing"; PlayerPrefs.SetString(tombstone, pos); } m_Animator = player.GetComponent(); m_CurrentClipInfo = this.m_Animator.GetCurrentAnimatorClipInfo(0); m_ClipName = m_CurrentClipInfo[0].clip.name; } void OnTriggerEnter2D(Collider2D collision) { ///For attacking player if (collision.tag == "HitboxTop") { if(m_ClipName == "IdleUp" || m_ClipName =="WalkUp") { if (position == "start" && goal != "set") { temp.x = x; temp.y = y + 1; goal = "set"; pos = "top"; } else if (position == "bottom" && goal != "set") { temp.x = x; temp.y = y; goal = "set"; pos = "start"; } } } else if (collision.tag == "HitboxBottom") { if (m_ClipName == "IdleDown" || m_ClipName == "WalkDown") { if (position == "start" && goal != "set") { temp.x = x; temp.y = y - 1; goal = "set"; pos = "bottom"; } else if (position == "top" && goal != "set") { temp.x = x; temp.y = y; goal = "set"; pos = "start"; } } } else if (collision.tag == "HitboxRight") { if (m_ClipName == "IdleRight" || m_ClipName == "WalkRight") { if (position == "start" && goal != "set") { temp.x = x + 1; temp.y = y; goal = "set"; pos = "right"; } else if (position == "left" && goal != "set") { temp.x = x; temp.y = y; goal = "set"; pos = "start"; } } } else if (collision.tag == "HitboxLeft") { if (m_ClipName == "IdleLeft" || m_ClipName == "WalkLeft") { if (position == "start" && goal != "set") { temp.x = x - 1; temp.y = y; goal = "set"; pos = "left"; } else if (position == "right" && goal != "set") { temp.x = x; temp.y = y; goal = "set"; pos = "start"; } } } } }