47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using DragonLi.Core;
|
|
using UnityEngine;
|
|
|
|
[RequireComponent(typeof(Rigidbody))]
|
|
public class PoisonBall : MonoBehaviour
|
|
{
|
|
public GameObject poisonPoolPrefab;
|
|
public float flightTime = 1.2f;
|
|
|
|
private Rigidbody rb;
|
|
|
|
public float poolDamage;
|
|
public float poolTime;
|
|
|
|
void Awake()
|
|
{
|
|
rb = GetComponent<Rigidbody>();
|
|
rb.useGravity = true;
|
|
}
|
|
|
|
public void Launch(Vector3 start, Vector3 target,float damage,float dieTime)
|
|
{
|
|
transform.position = start;
|
|
rb.velocity = CalculateVelocity(start, target, flightTime);
|
|
poolDamage = damage;
|
|
poolTime = dieTime;
|
|
}
|
|
|
|
Vector3 CalculateVelocity(Vector3 start, Vector3 target, float time)
|
|
{
|
|
Vector3 displacement = target - start;
|
|
Vector3 horizontal = new Vector3(displacement.x, 0, displacement.z);
|
|
|
|
float vy = displacement.y / time - 0.5f * Physics.gravity.y * time;
|
|
return horizontal / time + Vector3.up * vy;
|
|
}
|
|
|
|
private void OnCollisionEnter(Collision collision)
|
|
{
|
|
if (collision.gameObject.tag == "Ground"|| collision.gameObject.tag == "Player")
|
|
{
|
|
GameObject ball= Instantiate(poisonPoolPrefab, transform.position.ReflectVectorXOZ(), Quaternion.identity);
|
|
ball.GetComponent<PoisonPool>().SetDamage(poolDamage, poolTime);
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
} |