diff options
author | chai <chaifix@163.com> | 2021-09-04 14:02:24 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-09-04 14:02:24 +0800 |
commit | 34d01108e9f0c5488e8824f768c43801dd8ed4cc (patch) | |
tree | 8656926dc0fdb116590e295ce1038a192bc0eca3 /Assets/Scripts/Projectile/Projectile.cs | |
parent | 18a46c5eda8dad703eca557c6553f7f0ed3461af (diff) |
*misc
Diffstat (limited to 'Assets/Scripts/Projectile/Projectile.cs')
-rw-r--r-- | Assets/Scripts/Projectile/Projectile.cs | 59 |
1 files changed, 41 insertions, 18 deletions
diff --git a/Assets/Scripts/Projectile/Projectile.cs b/Assets/Scripts/Projectile/Projectile.cs index a6411f5f..ba325302 100644 --- a/Assets/Scripts/Projectile/Projectile.cs +++ b/Assets/Scripts/Projectile/Projectile.cs @@ -4,16 +4,18 @@ using UnityEngine; public struct ProjectileInfo
{
- public UnitController owner;
+ public string name;
+ public string tag;
+ public EventProjectile.EMoveType moveType;
+ public UnitController owner;
public Vector3 position;
public Vector3 rotation;
public Vector3 scale;
- public Vector3 direction;
public Vector3 velocity;
- public bool towardDirection;
+ public Vector3 acceleration;
+ public bool towardDirection;
public float lifetime;
public bool useGravity;
- public float gravity;
public string sparkPath;
}
@@ -35,9 +37,17 @@ public class Projectile : MonoBehaviour public Box colliderGrid;
public Vector3 slice;
- #endregion
+ #endregion
- [HideInInspector]
+ //名字,可以用来识别这个projectile
+ public new string name;
+
+ //标签,可以用来做一些标记
+ public new string tag;
+
+ public EventProjectile.EMoveType moveType;
+
+ [HideInInspector]
public UnitController owner;
[HideInInspector]
@@ -46,10 +56,10 @@ public class Projectile : MonoBehaviour [HideInInspector]
public Vector3 velocity; // 初始速度
- [HideInInspector]
- public float gravity;
+ [HideInInspector]
+ public Vector3 acceleration; // 加速度
- [HideInInspector]
+ [HideInInspector]
public bool towardDirection; // foward朝向运动的方向
[HideInInspector]
@@ -65,12 +75,16 @@ public class Projectile : MonoBehaviour public void Initialize(ProjectileInfo info)
{
+ this.name = info.name;
+ this.tag = info.tag;
+ this.moveType = info.moveType;
this.owner = info.owner;
this.transform.rotation = Quaternion.Euler(info.rotation);
this.transform.position = info.position;
this.transform.localScale.Scale(info.scale);
this.velocity = info.velocity;
- this.lifetime = info.lifetime;
+ this.acceleration = info.acceleration;
+ this.lifetime = info.lifetime;
this.sparkPath = info.sparkPath;
markDestroy = false;
@@ -92,15 +106,19 @@ public class Projectile : MonoBehaviour public void Update(float deltaTime)
{
- this.transform.position += this.velocity * deltaTime;
- time += deltaTime;
- if (time > this.lifetime || markDestroy)
- {
- DestroyImmediate(this.gameObject);
- }
- }
+ if(moveType == EventProjectile.EMoveType.Kinematic)
+ {
+ this.velocity += this.acceleration * deltaTime;
+ this.transform.position += this.velocity * deltaTime;
+ }
+ time += deltaTime;
+ if (time > this.lifetime || markDestroy)
+ {
+ DestroyImmediate(this.gameObject);
+ }
+ }
- void OnDestroy()
+ void OnDestroy()
{
ColliderRegistry.Instance.RemoveProjectile(this);
}
@@ -179,4 +197,9 @@ public class Projectile : MonoBehaviour }
}
+ public bool HasTag(string tag)
+ {
+ return this.tag != null && this.tag.Contains(tag);
+ }
+
}
\ No newline at end of file |