Skip to content

Commit

Permalink
Implementing root spike attack
Browse files Browse the repository at this point in the history
  • Loading branch information
someone42 committed Feb 5, 2023
1 parent 582bb56 commit 38be7af
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 86 deletions.
20 changes: 20 additions & 0 deletions Assets/Prefabs/TreeBoss.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ GameObject:
- component: {fileID: 23277807649979614}
- component: {fileID: 23277807649979615}
- component: {fileID: 4856363347904904803}
- component: {fileID: 7708893993313149470}
- component: {fileID: 3770758557608109406}
m_Layer: 0
m_Name: TreeBoss
Expand Down Expand Up @@ -124,6 +125,25 @@ MonoBehaviour:
isPlayer: 1
rootWavePrefab: {fileID: 4329808208691645257, guid: 74a322c512dbce546aac6550c4eb7c3b,
type: 3}
--- !u!114 &7708893993313149470
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 23277807649979601}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6608113060153e44b81f998fecb336e1, type: 3}
m_Name:
m_EditorClassIdentifier:
numRootSpikeSpawns: 10
initialDelay: 3
rootSpikeTimeInterval: 0.3
rootSpikeDistance: 4
initialDistanceFactor: 3
rootSpikePrefab: {fileID: 1396250162364260641, guid: 9a61359e32e7c374a93d60af9344f8fd,
type: 3}
--- !u!65 &3770758557608109406
BoxCollider:
m_ObjectHideFlags: 0
Expand Down
90 changes: 13 additions & 77 deletions Assets/Scenes/BossTestScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -194,80 +194,6 @@ MonoBehaviour:
m_Calls: []
m_LegacyBlendHint: 0
m_ComponentOwner: {fileID: 2017119448}
--- !u!1001 &355093411
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 1396250162364260641, guid: 9a61359e32e7c374a93d60af9344f8fd,
type: 3}
propertyPath: m_Name
value: BossSpike
objectReference: {fileID: 0}
- target: {fileID: 1396250162364260641, guid: 9a61359e32e7c374a93d60af9344f8fd,
type: 3}
propertyPath: m_TagString
value: Damaging
objectReference: {fileID: 0}
- target: {fileID: 3433720675850989519, guid: 9a61359e32e7c374a93d60af9344f8fd,
type: 3}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3433720675850989519, guid: 9a61359e32e7c374a93d60af9344f8fd,
type: 3}
propertyPath: m_LocalPosition.x
value: -3.17
objectReference: {fileID: 0}
- target: {fileID: 3433720675850989519, guid: 9a61359e32e7c374a93d60af9344f8fd,
type: 3}
propertyPath: m_LocalPosition.y
value: -0.6
objectReference: {fileID: 0}
- target: {fileID: 3433720675850989519, guid: 9a61359e32e7c374a93d60af9344f8fd,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3433720675850989519, guid: 9a61359e32e7c374a93d60af9344f8fd,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3433720675850989519, guid: 9a61359e32e7c374a93d60af9344f8fd,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3433720675850989519, guid: 9a61359e32e7c374a93d60af9344f8fd,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3433720675850989519, guid: 9a61359e32e7c374a93d60af9344f8fd,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3433720675850989519, guid: 9a61359e32e7c374a93d60af9344f8fd,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3433720675850989519, guid: 9a61359e32e7c374a93d60af9344f8fd,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3433720675850989519, guid: 9a61359e32e7c374a93d60af9344f8fd,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 9a61359e32e7c374a93d60af9344f8fd, type: 3}
--- !u!1 &539566950
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -549,7 +475,7 @@ Transform:
m_Children:
- {fileID: 564838221}
m_Father: {fileID: 0}
m_RootOrder: 4
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1610890213
GameObject:
Expand Down Expand Up @@ -664,7 +590,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &2017119447
GameObject:
Expand Down Expand Up @@ -791,7 +717,7 @@ PrefabInstance:
- target: {fileID: 23277807649979614, guid: 8d1a5c0cb9ffa9c4fb6011fd611520e5,
type: 3}
propertyPath: m_RootOrder
value: 3
value: 2
objectReference: {fileID: 0}
- target: {fileID: 23277807649979614, guid: 8d1a5c0cb9ffa9c4fb6011fd611520e5,
type: 3}
Expand Down Expand Up @@ -848,9 +774,19 @@ PrefabInstance:
propertyPath: chanceOfSpit
value: 0.1
objectReference: {fileID: 0}
- target: {fileID: 23277807649979615, guid: 8d1a5c0cb9ffa9c4fb6011fd611520e5,
type: 3}
propertyPath: chanceOfLaugh
value: 0.9
objectReference: {fileID: 0}
- target: {fileID: 23277807649979615, guid: 8d1a5c0cb9ffa9c4fb6011fd611520e5,
type: 3}
propertyPath: chanceOfSpike
value: 0
objectReference: {fileID: 0}
- target: {fileID: 23277807649979615, guid: 8d1a5c0cb9ffa9c4fb6011fd611520e5,
type: 3}
propertyPath: chanceOfSpecialIdle
value: 0.1
objectReference: {fileID: 0}
- target: {fileID: 1107897357665298954, guid: 8d1a5c0cb9ffa9c4fb6011fd611520e5,
Expand Down
75 changes: 75 additions & 0 deletions Assets/Scripts/RootSpikeSpawn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RootSpikeSpawn : MonoBehaviour
{
[Tooltip("Number of root spike objects")]
public int numRootSpikeSpawns = 8;
[Tooltip("Initial delay before the first spawn")]
public float initialDelay = 1.5f;
[Tooltip("Time interval in seconds between root spike spawns")]
public float rootSpikeTimeInterval = 0.5f;
[Tooltip("Distance interval between root spike spawns")]
public float rootSpikeDistance = 5.0f;
[Tooltip("Factor to apply for distance for first spawn")]
public float initialDistanceFactor = 1.5f;

[Tooltip("Put root spike prefab object here")]
public GameObject rootSpikePrefab;

public void Spawn()
{
StartCoroutine("SpawnSpikes");
}

IEnumerator SpawnSpikes()
{
GameObject[] rootSpikes = new GameObject[numRootSpikeSpawns];
yield return new WaitForSeconds(initialDelay);
for (int i = 0; i < numRootSpikeSpawns; i++)
{
Vector3 pos;
if (i == 0)
{
// Spawn to left of tree
pos = transform.position;
}
else
{
// Spawn to left of the last root
pos = rootSpikes[i - 1].transform.position;
}
float offset = rootSpikeDistance;
if (i == 0)
{
offset *= initialDistanceFactor;
}
pos += Vector3.left * offset;
rootSpikes[i] = Instantiate(rootSpikePrefab, transform);
rootSpikes[i].transform.position = pos;
yield return new WaitForSeconds(rootSpikeTimeInterval);
}
for (int i = 0; i < numRootSpikeSpawns; i++)
{
Destroy(rootSpikes[i]);
rootSpikes[i] = null;
if (i != (numRootSpikeSpawns - 1))
{
yield return new WaitForSeconds(rootSpikeTimeInterval * 0.75f);
}
}
}

// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/RootSpikeSpawn.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 5 additions & 9 deletions Assets/Scripts/TreeBossController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum States

private Animator animator;
private RootWaveSpawn rootWave;
private RootSpikeSpawn rootSpike;

private States currentState;
private float lastSpike;
Expand All @@ -45,6 +46,7 @@ void Start()
// The animator is in a child object so we need to use GetComponentInChildren instead of GetComponent
animator = GetComponentInChildren<Animator>();
rootWave = GetComponent<RootWaveSpawn>();
rootSpike = GetComponent<RootSpikeSpawn>();
animator.SetTrigger("StartLaugh");
// Because the animator is in a child object, we can't get it to call a function here,
// instead, use AnimationEventsHandler to forward the calls to our AnimationClipEnded method
Expand Down Expand Up @@ -82,7 +84,9 @@ private bool chooseNewState()
{
return false; // lockout
}
Debug.Log("StartLaugh");
animator.SetTrigger("StartLaugh");
rootSpike.Spawn();
lastSpike = Time.fixedTime;
}
else
Expand Down Expand Up @@ -128,12 +132,4 @@ private void AnimationClipEnded(string clipName)
successful = chooseNewState();
} while (!successful);
}

public void SpikeWave()
{
print("hello");
}

}


}

0 comments on commit 38be7af

Please sign in to comment.