1
This commit is contained in:
86
unity/Assets/Script/CombaSyatem/BulletObject.cs
Normal file
86
unity/Assets/Script/CombaSyatem/BulletObject.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BulletObject : MonoBehaviour
|
||||
{
|
||||
private bool initialied = false;
|
||||
|
||||
[SerializeField] private Vector2 startPos;
|
||||
private Vector2 midPos;
|
||||
private float percent = 0;
|
||||
private float percentSpeed = 0;
|
||||
[SerializeField] private float speed = 25;
|
||||
|
||||
|
||||
private Vector2 lastTargetPos;
|
||||
|
||||
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (initialied )
|
||||
{
|
||||
percent += percentSpeed * Time.deltaTime;
|
||||
if (percent >= 1)
|
||||
{
|
||||
percent = 1;
|
||||
}
|
||||
transform.position = UnityExpandFunction.Bezier(percent, startPos, midPos, lastTargetPos);
|
||||
}
|
||||
if(transform.position==new Vector3(lastTargetPos.x, lastTargetPos.y,0))
|
||||
{
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
|
||||
}
|
||||
public void Init(GameObject parent)
|
||||
{
|
||||
GameObject player = GameObject.FindGameObjectWithTag("Player");
|
||||
if(player!=null)
|
||||
{
|
||||
lastTargetPos = player.transform.position;
|
||||
|
||||
startPos = parent.transform.position+new Vector3(Random.Range(0,2), Random.Range(0, 2),0);
|
||||
|
||||
midPos = GetMiddlePostion(parent.transform.position, lastTargetPos);
|
||||
|
||||
percentSpeed = speed / (lastTargetPos - startPos).magnitude;
|
||||
|
||||
transform.position = startPos;
|
||||
|
||||
percent = 0;
|
||||
initialied = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ÖÐÐĵã
|
||||
/// </summary>
|
||||
/// <param name="a"></param>
|
||||
/// <param name="b"></param>
|
||||
/// <returns></returns>
|
||||
private Vector2 GetMiddlePostion(Vector2 a, Vector2 b)
|
||||
{
|
||||
Vector2 m = Vector2.Lerp(a,b,0.1f);
|
||||
Vector2 normal = Vector2.Perpendicular(a-b).normalized;
|
||||
|
||||
float rd = Random.Range(-2f,2f);
|
||||
float curveRatio = 15f;//Æ«ÒÆÖµ
|
||||
|
||||
return m + (a - b).normalized * curveRatio * rd * normal;
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if(collision.CompareTag("Player"))
|
||||
{
|
||||
if (collision.gameObject.GetComponentInChildren<CombaSystem>()._animator.CheckAnimationTag("Roll"))
|
||||
return;
|
||||
Debug.Log("»÷ÖÐ");
|
||||
collision.gameObject.GetComponentInChildren<CombaSystem>().TakeDamage(20);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user