using NodeCanvas.Framework; using Sirenix.OdinInspector; using System.Collections; using System.Collections.Generic; using UnityEngine; public class MoveController : MonoBehaviour { Rigidbody2D rigidbody2d; Blackboard blackboard; [LabelText("速度属性名称")] public string speedName = "speed"; [LabelText("方向属性名称")] public string directionName = "moveDirection"; void Start() { rigidbody2d = GetComponent(); if (rigidbody2d == null) { Debug.LogError("Rigidbody2D组件为空!"); return; } blackboard = GetComponent(); if (blackboard == null) { Debug.LogError("Blackboard组件为空!"); return; } } private void Update() { if(rigidbody2d && blackboard && blackboard.GetVariableValue(directionName) != Vector2.zero) { MovePosition(); } } private void MovePosition() { float speed = blackboard.GetVariableValue(speedName); Vector2 tempMove = blackboard.GetVariableValue(directionName) * (0.02f * speed); rigidbody2d.MovePosition(rigidbody2d.position + tempMove); } }