82 lines
1.5 KiB
C#
82 lines
1.5 KiB
C#
using UnityEngine;
|
|
namespace G
|
|
{
|
|
public class Flower_cannon : MonoBehaviour
|
|
{
|
|
private Animation myanimation;
|
|
|
|
public Transform cannonball;
|
|
|
|
public Transform trap;
|
|
|
|
private Vector3 ballPos;
|
|
|
|
private Vector3 targetPos;
|
|
|
|
private Vector3 ballPosStartPos;
|
|
|
|
private Transform target;
|
|
|
|
private float dy;
|
|
|
|
private float posY;
|
|
|
|
private bool cannonshot;
|
|
|
|
private EntityTrap script_trap;
|
|
|
|
private void Start()
|
|
{
|
|
myanimation = base.GetComponent<Animation>();
|
|
myanimation["flower"].speed = 0.1f;
|
|
myanimation["flower_idle"].speed = 0.001f;
|
|
target = GameObject.FindWithTag("Player").transform;
|
|
//script_trap = trap.GetComponent<Trap_Extreme>();
|
|
ballPosStartPos = cannonball.position;
|
|
}
|
|
|
|
public void StartShoot()
|
|
{
|
|
myanimation.Play("flower");
|
|
}
|
|
|
|
public void FisnishShoot()
|
|
{
|
|
myanimation.Stop();
|
|
myanimation.Play("flower_idle");
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (cannonshot)
|
|
{
|
|
ballPos = Vector3.MoveTowards(ballPos, targetPos, Time.deltaTime);
|
|
posY += Time.deltaTime * dy;
|
|
dy -= Time.deltaTime * 2f;
|
|
ballPos.y = posY;
|
|
if (ballPos.y < 0f)
|
|
{
|
|
cannonshot = false;
|
|
//script_trap.DirectFire(ballPos);
|
|
//trap.GetChild(0).particleEmitter().Emit();
|
|
//trap.GetChild(1).particleEmitter().Emit();
|
|
cannonball.position = Vector3.up * 34f;
|
|
}
|
|
else
|
|
{
|
|
cannonball.position = ballPos;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void CannonShot()
|
|
{
|
|
ballPos = ballPosStartPos;
|
|
targetPos = target.position;
|
|
dy = 1.5f;
|
|
posY = ballPosStartPos.y;
|
|
cannonshot = true;
|
|
}
|
|
}
|
|
}
|