projectile damaging + robots can die:)

This commit is contained in:
Sveske Juice 2024-04-20 20:48:38 +02:00
parent 666e6269a8
commit 0db4c49568
10 changed files with 151 additions and 6 deletions

View File

@ -13,6 +13,7 @@ GameObject:
- component: {fileID: 5408793041970514069}
- component: {fileID: 58437666630366278}
- component: {fileID: 4851113807957284959}
- component: {fileID: 8700343489547611766}
m_Layer: 6
m_Name: Bullet
m_TagString: Untagged
@ -133,3 +134,18 @@ Rigidbody:
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!114 &8700343489547611766
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2962360034595352958}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a98521a4b559621438fc196adc605f3b, type: 3}
m_Name:
m_EditorClassIdentifier:
bounciness: 0.516
damage: 10
wallRebounces: 4

View File

@ -73,6 +73,10 @@ PrefabInstance:
type: 3}
insertIndex: -1
addedObject: {fileID: 7883233016828513649}
- targetCorrespondingSourceObject: {fileID: 919132149155446097, guid: eb5e13df78999ef878da1db5c63224e2,
type: 3}
insertIndex: -1
addedObject: {fileID: 5565472806559733162}
m_SourcePrefab: {fileID: 100100000, guid: eb5e13df78999ef878da1db5c63224e2, type: 3}
--- !u!1 &872127579833310669 stripped
GameObject:
@ -95,7 +99,40 @@ MonoBehaviour:
startHealth: 100
OnHealthZero:
m_PersistentCalls:
m_Calls: []
m_Calls:
- m_Target: {fileID: 7883233016828513649}
m_TargetAssemblyTypeName: HealthComponent, Assembly-CSharp
m_MethodName: SimpleKill
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
OnHealthChange:
m_PersistentCalls:
m_Calls: []
--- !u!65 &5565472806559733162
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 872127579833310669}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}

View File

@ -231,6 +231,36 @@ PrefabInstance:
propertyPath: m_Name
value: BlackHole
objectReference: {fileID: 0}
- target: {fileID: 5565472806559733162, guid: f54a14318952c90c5b47a300aedb0d15,
type: 3}
propertyPath: m_Size.x
value: 0.5101528
objectReference: {fileID: 0}
- target: {fileID: 5565472806559733162, guid: f54a14318952c90c5b47a300aedb0d15,
type: 3}
propertyPath: m_Size.y
value: 1.8364654
objectReference: {fileID: 0}
- target: {fileID: 5565472806559733162, guid: f54a14318952c90c5b47a300aedb0d15,
type: 3}
propertyPath: m_Size.z
value: 0.5177386
objectReference: {fileID: 0}
- target: {fileID: 5565472806559733162, guid: f54a14318952c90c5b47a300aedb0d15,
type: 3}
propertyPath: m_Center.x
value: -0.022192955
objectReference: {fileID: 0}
- target: {fileID: 5565472806559733162, guid: f54a14318952c90c5b47a300aedb0d15,
type: 3}
propertyPath: m_Center.y
value: -0.0720216
objectReference: {fileID: 0}
- target: {fileID: 5565472806559733162, guid: f54a14318952c90c5b47a300aedb0d15,
type: 3}
propertyPath: m_Center.z
value: -0.008693576
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects:

View File

@ -383,7 +383,7 @@ Transform:
m_GameObject: {fileID: 2676689439087408815}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0.00723}
m_LocalPosition: {x: 0, y: 0, z: 0.00846}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
@ -994,6 +994,36 @@ PrefabInstance:
propertyPath: m_Name
value: Turret
objectReference: {fileID: 0}
- target: {fileID: 5565472806559733162, guid: f54a14318952c90c5b47a300aedb0d15,
type: 3}
propertyPath: m_Size.x
value: 0.5204178
objectReference: {fileID: 0}
- target: {fileID: 5565472806559733162, guid: f54a14318952c90c5b47a300aedb0d15,
type: 3}
propertyPath: m_Size.y
value: 1.2033536
objectReference: {fileID: 0}
- target: {fileID: 5565472806559733162, guid: f54a14318952c90c5b47a300aedb0d15,
type: 3}
propertyPath: m_Size.z
value: 0.6565219
objectReference: {fileID: 0}
- target: {fileID: 5565472806559733162, guid: f54a14318952c90c5b47a300aedb0d15,
type: 3}
propertyPath: m_Center.x
value: -0.02208674
objectReference: {fileID: 0}
- target: {fileID: 5565472806559733162, guid: f54a14318952c90c5b47a300aedb0d15,
type: 3}
propertyPath: m_Center.y
value: -0.07302019
objectReference: {fileID: 0}
- target: {fileID: 5565472806559733162, guid: f54a14318952c90c5b47a300aedb0d15,
type: 3}
propertyPath: m_Center.z
value: -0.05310279
objectReference: {fileID: 0}
- target: {fileID: 8365322460670124409, guid: f54a14318952c90c5b47a300aedb0d15,
type: 3}
propertyPath: m_Name

View File

@ -1243,7 +1243,7 @@ PrefabInstance:
- target: {fileID: 7348612162646443967, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
type: 3}
propertyPath: m_LocalRotation.w
value: -0.1380528
value: -0.13805284
objectReference: {fileID: 0}
- target: {fileID: 7348612162646443967, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
type: 3}
@ -1258,7 +1258,7 @@ PrefabInstance:
- target: {fileID: 7348612162646443967, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
type: 3}
propertyPath: m_LocalRotation.z
value: -0.13815574
value: -0.13815573
objectReference: {fileID: 0}
- target: {fileID: 8882344377078016156, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
type: 3}

View File

@ -106,7 +106,6 @@ public class AimTower : Tower
ghosts[poolIdx].transform.position = ghostPos;
ghosts[poolIdx].SetActive(true);
poolIdx = (poolIdx + 1) % trajectoryObjectPoolSize;
Debug.Log($"pool idx: {poolIdx}");
}
else
{

View File

@ -9,6 +9,15 @@ public class Projectile : MonoBehaviour
private Collider projCol;
[SerializeField, Range(0, 50)]
private int damage = 10;
[SerializeField]
private int wallRebounces = 4;
private int hitWalls = 0;
public HealthComponent comingFrom;
private void Awake()
{
projCol = GetComponent<Collider>();
@ -19,4 +28,22 @@ public class Projectile : MonoBehaviour
projCol.material = pMat;
}
private void OnCollisionEnter(Collision collision)
{
HealthComponent hitHealthComp = collision.gameObject.GetComponent<HealthComponent>();
if (hitHealthComp == comingFrom) return;
if (hitHealthComp)
{
hitHealthComp.TakeDamage(damage);
Destroy(gameObject);
}
else
{
if (++hitWalls == wallRebounces)
{
Destroy(gameObject);
}
}
}
}

View File

@ -29,7 +29,7 @@ public class ProjectileTower : AimTower
Debug.DrawRay(transform.position, horizontalArc.ToKnobVector, Color.red, attackSecondsDelay);
Debug.DrawRay(transform.position, verticalArc.ToKnobVector, Color.green, attackSecondsDelay);
Debug.DrawRay(transform.position, AimDirection, Color.yellow, attackSecondsDelay);
projectileSpawner.RunBulletSequence(barrel.transform.position, transform.up, AimDirection, projectileSequence);
projectileSpawner.RunBulletSequence(barrel.Tip.position, transform.up, AimDirection, projectileSequence);
} while (true);
}
}

View File

@ -28,5 +28,10 @@ public class HealthComponent : MonoBehaviour
if (currentHealth == 0)
OnHealthZero?.Invoke();
}
public void SimpleKill()
{
Destroy(gameObject);
}
}

View File

@ -45,6 +45,7 @@ public class ProjectileSpawner : MonoBehaviour
projectile.transform.up = bulletDir;
projectile.GetComponent<Rigidbody>().AddForce(bulletDir * bulletPattern.Speed);
projectile.GetComponent<Projectile>().comingFrom = GetComponent<HealthComponent>();
if (bulletPattern.Burst)
yield return new WaitForSeconds(bulletPattern.BurstDelay);