using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CardBehavior : MonoBehaviour
{
private Vector2 primitivePos;
private Vector2 primitiveRot;
private bool canMove;
private Vector2 targetPos;
private float distance;
void Start()
{
distance = 0.4f;
canMove = false;
primitivePos = transform.position;
targetPos = new Vector2(0.7f, 0);
}
void Update()
{
Debug.Log("Update前是" + canMove);
if (canMove)
{
MoveTo(targetPos, distance);
}
}
public void MoveTo(Vector2 targetPos, float dis)
{
if (Vector2.Distance(transform.position, targetPos) > dis)
{
transform.Translate(Vector2.right * Time.deltaTime * 3);
Debug.Log("MoveTo过程中是" + canMove);
}
else
{
canMove = false;
Debug.Log("Move结束是" + canMove);
//等待是攻击还是返回
Invoke("GoBack", 0.1f);
}
}
private void GoBack()
{
// canMove = true;
// targetPos = primitivePos;
// distance = 0.01f;
transform.position = primitivePos;
canMove = true;
Debug.Log("GoBack后是" + canMove);
}
public void OnAttackButton()
{
canMove = true;
Debug.Log("OnAtkBtn后是" + canMove);
}
}
看了好几遍,没看出逻辑有什么问题,建议重启一下再试试
重启了还是这样,补充一下这个脚本是挂在还没实例化的prefab上的