Enemy spawning

This commit is contained in:
Norbi Peti 2020-11-06 23:00:49 +01:00
parent 338ab550f0
commit 78ed658fce
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
5 changed files with 88 additions and 79 deletions

View file

@ -57,6 +57,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="Assets\Scripts\CameraController.cs" /> <Compile Include="Assets\Scripts\CameraController.cs" />
<Compile Include="Assets\Scripts\EnemyController.cs" /> <Compile Include="Assets\Scripts\EnemyController.cs" />
<Compile Include="Assets\Scripts\EnemySpawner.cs" />
<Compile Include="Assets\Scripts\OwnCharacterController.cs" /> <Compile Include="Assets\Scripts\OwnCharacterController.cs" />
<Compile Include="Assets\Scripts\Parallaxing.cs" /> <Compile Include="Assets\Scripts\Parallaxing.cs" />
<Compile Include="Assets\Scripts\RocketScript.cs" /> <Compile Include="Assets\Scripts\RocketScript.cs" />

View file

@ -144,4 +144,4 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
target: {fileID: 0} target: {fileID: 0}
speed: 1.1 speed: 6

View file

@ -615,6 +615,36 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
smoothing: 1 smoothing: 1
--- !u!1 &1692511763
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1692511764}
m_Layer: 0
m_Name: EnemySpawn
m_TagString: Untagged
m_Icon: {fileID: 5132851093641282708, guid: 0000000000000000d000000000000000, type: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1692511764
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1692511763}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.67, y: 2.4, z: -2.796909}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &2053847420 --- !u!1 &2053847420
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -629,6 +659,7 @@ GameObject:
- component: {fileID: 2053847423} - component: {fileID: 2053847423}
- component: {fileID: 2053847425} - component: {fileID: 2053847425}
- component: {fileID: 2053847426} - component: {fileID: 2053847426}
- component: {fileID: 2053847427}
m_Layer: 0 m_Layer: 0
m_Name: Character m_Name: Character
m_TagString: Untagged m_TagString: Untagged
@ -775,82 +806,21 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
prefab: {fileID: 5991448782009560204, guid: 7debf3c35b28387fdbec1c1c9942afae, type: 3} prefab: {fileID: 5991448782009560204, guid: 7debf3c35b28387fdbec1c1c9942afae, type: 3}
firePoint: {fileID: 1043406434} firePoint: {fileID: 1043406434}
--- !u!1001 &7250562544796225521 --- !u!114 &2053847427
PrefabInstance: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
serializedVersion: 2 m_CorrespondingSourceObject: {fileID: 0}
m_Modification: m_PrefabInstance: {fileID: 0}
m_TransformParent: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Modifications: m_GameObject: {fileID: 2053847420}
- target: {fileID: -1018939148389277147, guid: ef6e23d6fe1e28e8c809679081854c6a, m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: aa26aed626e74c85909419c3dde3ced8, type: 3}
m_Name:
m_EditorClassIdentifier:
spawnPos: {fileID: 1692511764}
timeBetweenSpawns: 5
maxEnemyCount: 3
enemyPrefab: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
type: 3} type: 3}
propertyPath: target target: {fileID: 2053847422}
value:
objectReference: {fileID: 2053847422}
- target: {fileID: -1018939148389277147, guid: ef6e23d6fe1e28e8c809679081854c6a,
type: 3}
propertyPath: speed
value: 6
objectReference: {fileID: 0}
- target: {fileID: 7250562544566202694, guid: ef6e23d6fe1e28e8c809679081854c6a,
type: 3}
propertyPath: m_Name
value: Enemy
objectReference: {fileID: 0}
- target: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
type: 3}
propertyPath: m_LocalPosition.x
value: -0.32
objectReference: {fileID: 0}
- target: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
type: 3}
propertyPath: m_LocalPosition.y
value: 2.49
objectReference: {fileID: 0}
- target: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
type: 3}
propertyPath: m_RootOrder
value: 5
objectReference: {fileID: 0}
- target: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: ef6e23d6fe1e28e8c809679081854c6a, type: 3}

View file

@ -0,0 +1,35 @@
using System;
using UnityEngine;
using Random = System.Random;
public class EnemySpawner : MonoBehaviour
{
public Transform spawnPos;
public float timeBetweenSpawns;
public short maxEnemyCount;
public Transform enemyPrefab;
public Transform target;
private Vector3 _diff;
private float _lastSpawn;
private readonly Random _random = new Random();
private void Start()
{
_diff = spawnPos.position - transform.position;
enemyPrefab.GetComponent<EnemyController>().target = target;
}
private void FixedUpdate()
{
if (Time.fixedTime - _lastSpawn > timeBetweenSpawns && _random.Next(2) == 1)
{
short count = (short) _random.Next(maxEnemyCount);
for (int i = 0; i < count; i++)
{
var pos = transform.position + _diff;
Instantiate(enemyPrefab).position = new Vector3(pos.x, spawnPos.position.y, pos.z);
}
_lastSpawn = Time.fixedTime;
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: aa26aed626e74c85909419c3dde3ced8
timeCreated: 1604698494