xi/Assets/scripts/wupin.cs
2024-12-04 09:22:45 +08:00

52 lines
1.5 KiB
C#

using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class wupin : MonoBehaviour
{
public float distance = 20f;
public float Desdis = 20f;
public float addMP = 5f;
void Start()
{
//TodoÎïÆ·ÌøԾЧ¹û
Tweener upTween = this.transform.DOMove(new Vector3(this.transform.position.x, this.transform.position.y + 30, this.transform.position.z), 0.5f);
upTween.OnComplete(() =>
{
// ÏòÏÂÒƶ¯
this.transform.DOMove(new Vector3(this.transform.position.x, this.transform.position.y - 30, this.transform.position.z), 0.5f);
});
}
// Update is called once per frame
void Update()
{
MoveToPlayer();
}
void MoveToPlayer()
{
Transform player = GameObject.FindWithTag("Player").transform;
float dis = Vector3.Distance(player.position, this.transform.position);
if (dis < distance)
{
this.transform.DOMove(player.position, 1.5f);
}
if (dis < Desdis)
{
//Todo
player.GetComponent<playercontroller>().currentMP += addMP;
if(player.GetComponent<playercontroller>().currentMP>= player.GetComponent<playercontroller>().totalMP)
{
player.GetComponent<playercontroller>().currentMP = player.GetComponent<playercontroller>().totalMP;
}
Destroy(this.gameObject);
}
}
}