Add artist shooting, and refactor generation movment
This commit is contained in:
parent
2dad7631dd
commit
08ea2e0dcf
@ -26,7 +26,7 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2276488776047960095}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: -0.4975915, y: -0.11709992, z: 0}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
@ -97,3 +97,5 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 06caeb0582820f948af0d6f38028c18c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
range: 50
|
||||
projectile: {fileID: 3544353787361441734, guid: aa1ba1d671c82454aa7a59fc067bba98, type: 3}
|
||||
|
148
Assets/Prefabs/ArtistPencilAttack.prefab
Normal file
148
Assets/Prefabs/ArtistPencilAttack.prefab
Normal file
@ -0,0 +1,148 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &3544353787361441734
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 724014420718400120}
|
||||
- component: {fileID: 2790118073472331148}
|
||||
- component: {fileID: -4088027269952991048}
|
||||
- component: {fileID: -3318894246017771297}
|
||||
- component: {fileID: 1388709940240671698}
|
||||
m_Layer: 0
|
||||
m_Name: ArtistPencilAttack
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &724014420718400120
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3544353787361441734}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 0.4, y: 0.1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!212 &2790118073472331148
|
||||
SpriteRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3544353787361441734}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 0
|
||||
m_ReceiveShadows: 0
|
||||
m_DynamicOccludee: 1
|
||||
m_StaticShadowCaster: 0
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 0
|
||||
m_RayTraceProcedural: 0
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
m_StaticBatchRoot: {fileID: 0}
|
||||
m_ProbeAnchor: {fileID: 0}
|
||||
m_LightProbeVolumeOverride: {fileID: 0}
|
||||
m_ScaleInLightmap: 1
|
||||
m_ReceiveGI: 1
|
||||
m_PreserveUVs: 0
|
||||
m_IgnoreNormalsForChartDetection: 0
|
||||
m_ImportantGI: 0
|
||||
m_StitchLightmapSeams: 1
|
||||
m_SelectedEditorRenderState: 0
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_SortingLayerID: 1035096185
|
||||
m_SortingLayer: -1
|
||||
m_SortingOrder: 0
|
||||
m_Sprite: {fileID: 7482667652216324306, guid: 311925a002f4447b3a28927169b83ea6, type: 3}
|
||||
m_Color: {r: 1, g: 0.92054325, b: 0, a: 1}
|
||||
m_FlipX: 0
|
||||
m_FlipY: 0
|
||||
m_DrawMode: 0
|
||||
m_Size: {x: 1, y: 1}
|
||||
m_AdaptiveModeThreshold: 0.5
|
||||
m_SpriteTileMode: 0
|
||||
m_WasSpriteAssigned: 1
|
||||
m_MaskInteraction: 0
|
||||
m_SpriteSortPoint: 0
|
||||
--- !u!50 &-4088027269952991048
|
||||
Rigidbody2D:
|
||||
serializedVersion: 4
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3544353787361441734}
|
||||
m_BodyType: 1
|
||||
m_Simulated: 1
|
||||
m_UseFullKinematicContacts: 0
|
||||
m_UseAutoMass: 0
|
||||
m_Mass: 1
|
||||
m_LinearDrag: 0
|
||||
m_AngularDrag: 0.05
|
||||
m_GravityScale: 1
|
||||
m_Material: {fileID: 0}
|
||||
m_Interpolate: 0
|
||||
m_SleepingMode: 0
|
||||
m_CollisionDetection: 0
|
||||
m_Constraints: 0
|
||||
--- !u!61 &-3318894246017771297
|
||||
BoxCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3544353787361441734}
|
||||
m_Enabled: 1
|
||||
m_Density: 1
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 1
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_SpriteTilingProperty:
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
pivot: {x: 0.5, y: 0.5}
|
||||
oldSize: {x: 1, y: 1}
|
||||
newSize: {x: 1, y: 1}
|
||||
adaptiveTilingThreshold: 0.5
|
||||
drawMode: 0
|
||||
adaptiveTiling: 0
|
||||
m_AutoTiling: 0
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 1, y: 1}
|
||||
m_EdgeRadius: 0
|
||||
--- !u!114 &1388709940240671698
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3544353787361441734}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 7cdb7de3f3533494eae1b220ca0aebe1, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
7
Assets/Prefabs/ArtistPencilAttack.prefab.meta
Normal file
7
Assets/Prefabs/ArtistPencilAttack.prefab.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa1ba1d671c82454aa7a59fc067bba98
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -28,7 +28,7 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1458536803320539101}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: -0.4975915, y: -0.11709992, z: 0}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
@ -99,6 +99,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 6d151e6102b72db4590ce83309573f1c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
speed: 1
|
||||
--- !u!50 &7146678828090736945
|
||||
Rigidbody2D:
|
||||
serializedVersion: 4
|
||||
|
@ -28,7 +28,7 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2624247600710686983}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: -0.7311517, y: 0.074633844, z: 0}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 0.1, y: 0.1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
|
@ -303,7 +303,7 @@ SpriteRenderer:
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_SortingLayerID: -22961053
|
||||
m_SortingLayer: -1
|
||||
m_SortingLayer: -2
|
||||
m_SortingOrder: 0
|
||||
m_Sprite: {fileID: 5854342148761561055, guid: 8cdb315d4968ef847a63e52bd8847e5b, type: 3}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
@ -486,7 +486,7 @@ MonoBehaviour:
|
||||
m_Intensity: 1
|
||||
m_LightVolumeIntensity: 1
|
||||
m_LightVolumeIntensityEnabled: 0
|
||||
m_ApplyToSortingLayers: 0000000063a4a1fe
|
||||
m_ApplyToSortingLayers: 63a4a1fe7950b23d00000000
|
||||
m_LightCookieSprite: {fileID: 0}
|
||||
m_DeprecatedPointLightCookieSprite: {fileID: 0}
|
||||
m_LightOrder: 0
|
||||
@ -730,7 +730,7 @@ PrefabInstance:
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
|
||||
propertyPath: m_LocalPosition.z
|
||||
value: -0.0487628
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
|
||||
propertyPath: m_LocalRotation.w
|
||||
|
@ -1,5 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ArtistController : MonoBehaviour {
|
||||
public int range = 50;
|
||||
public int projectileSpeed = 5;
|
||||
public GameObject projectile;
|
||||
|
||||
private Queue<GameObject> enemyQueue;
|
||||
void Start() {
|
||||
InvokeRepeating(nameof(fireAttack), 0, 1);
|
||||
}
|
||||
|
||||
public void setEnemyQueue(Queue<GameObject> enemyQueueIn) {
|
||||
enemyQueue = enemyQueueIn;
|
||||
}
|
||||
|
||||
// Look through all of the queue, and find the distance between each enemy and the artist.
|
||||
// Keep track of the enemy with the lowest distance, and after you have looped through the entire queue,
|
||||
// Initiate a new instance of the projectile game object, from the artists position, in the direction of the enemy.
|
||||
private void fireAttack() {
|
||||
if (enemyQueue.Count == 0) return; // If there are no enemies in the queue, return.
|
||||
if (enemyQueue.Peek() == null) return; // If the first enemy in the queue is null, return.
|
||||
|
||||
float lowestDistance = range;
|
||||
GameObject enemyTarget = null;
|
||||
|
||||
foreach (var enemy in enemyQueue) {
|
||||
var distance = Vector3.Distance(enemy.transform.position, transform.position);
|
||||
if (distance < lowestDistance) {
|
||||
lowestDistance = distance;
|
||||
enemyTarget = enemy;
|
||||
}
|
||||
}
|
||||
|
||||
if (enemyTarget == null) return; // If there are no enemies in range, return.
|
||||
|
||||
//Find the vector that points from the artist to the enemy.
|
||||
var heading = enemyTarget.transform.position - transform.position;
|
||||
//Find the angle between the artist and the enemy.
|
||||
var angle = Mathf.Atan2(heading.y, heading.x) * Mathf.Rad2Deg;
|
||||
//Create a quaternion (rotation) based on the angle.
|
||||
var q = Quaternion.Euler(0,0,angle);
|
||||
var projectileInstance = Instantiate(projectile, transform.position, q);
|
||||
projectileInstance.GetComponent<StandardProjectileController>().setSpeed(projectileSpeed);
|
||||
}
|
||||
}
|
@ -4,37 +4,43 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GenerationController : MonoBehaviour {
|
||||
internal GameObject[] waypoints;
|
||||
public float speed;
|
||||
private GameObject[] waypoints;
|
||||
private int waypointIndex = 1;
|
||||
|
||||
private Rigidbody2D rb;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start() {
|
||||
rb = GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() { }
|
||||
|
||||
private void FixedUpdate() {
|
||||
if (waypointIndex < waypoints.Length) {
|
||||
var target = waypoints[waypointIndex].transform.position;
|
||||
var direction = target - transform.position;
|
||||
var f = transform.position + direction.normalized * 0.1f;
|
||||
rb.MovePosition(f);
|
||||
} else if (waypointIndex >= waypoints.Length) {
|
||||
Destroy(gameObject);
|
||||
}
|
||||
moveToNextWaypoint();
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D col) {
|
||||
if (col.gameObject == waypoints[waypointIndex]) {
|
||||
waypointIndex++;
|
||||
moveToNextWaypoint();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setWaypoints(GameObject[] waypointsIn) {
|
||||
waypoints = waypointsIn;
|
||||
}
|
||||
|
||||
private void moveToNextWaypoint() {
|
||||
if (waypointIndex < waypoints.Length) {
|
||||
// Point towards the next waypoint
|
||||
var heading = waypoints[waypointIndex].transform.position - transform.position;
|
||||
var distance = heading.magnitude;
|
||||
var direction = heading / distance;
|
||||
var angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
|
||||
var q = Quaternion.Euler(0,0,angle);
|
||||
transform.rotation = q;
|
||||
|
||||
//Move towards the next waypoint, taking into account the speed variable
|
||||
rb.velocity = direction * speed;
|
||||
} else if (waypointIndex >= waypoints.Length) {
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
@ -18,7 +18,8 @@ public class LevelController : MonoBehaviour {
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
if (Input.GetMouseButtonDown(0)) {
|
||||
Instantiate(artist, Camera.main.ScreenToWorldPoint(Input.mousePosition) + Vector3.forward, Quaternion.identity);
|
||||
var a = Instantiate(artist, Camera.main.ScreenToWorldPoint(Input.mousePosition) + (Vector3.forward * 10), Quaternion.identity);
|
||||
a.GetComponent<ArtistController>().setEnemyQueue(enemies);
|
||||
}
|
||||
}
|
||||
|
||||
|
27
Assets/Scripts/StandardProjectileController.cs
Normal file
27
Assets/Scripts/StandardProjectileController.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class StandardProjectileController : MonoBehaviour {
|
||||
private float speed;
|
||||
private Rigidbody2D rb;
|
||||
|
||||
void Start() {
|
||||
rb = GetComponent<Rigidbody2D>();
|
||||
rb.velocity = transform.right * speed ;
|
||||
}
|
||||
|
||||
void Update() {
|
||||
|
||||
}
|
||||
|
||||
public void setSpeed( float speedIn) {
|
||||
speed = speedIn;
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D col) {
|
||||
Destroy(col.gameObject);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
11
Assets/Scripts/StandardProjectileController.cs.meta
Normal file
11
Assets/Scripts/StandardProjectileController.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7cdb7de3f3533494eae1b220ca0aebe1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -41,6 +41,9 @@ TagManager:
|
||||
- name: Background
|
||||
uniqueID: 4272006243
|
||||
locked: 0
|
||||
- name: Attacks
|
||||
uniqueID: 1035096185
|
||||
locked: 0
|
||||
- name: Default
|
||||
uniqueID: 0
|
||||
locked: 0
|
||||
|
Loading…
Reference in New Issue
Block a user