Add monster awareness
Now monsters should be aware of the player if he's in 3 tiles from them
This commit is contained in:
parent
2dc6c440e1
commit
147f063d3f
6 changed files with 27 additions and 49 deletions
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: ef3d86d84c224344a94715cdfa9fe32c
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 043f304edcc831c4ea9fcf0e1a2e520d
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 0460346d99d385241a6d87bbd10aceb8
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: e823a56cb429e4b49becdc740fba66b9
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -15,14 +15,19 @@ public class Monster : MonoBehaviour
|
||||||
|
|
||||||
private Map map;
|
private Map map;
|
||||||
|
|
||||||
|
private Player player;
|
||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
map = GameObject.FindGameObjectWithTag("Map").GetComponent<Map>();
|
map = GameObject.FindGameObjectWithTag("Map").GetComponent<Map>();
|
||||||
|
player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
|
||||||
hasSpottedPlayer = false;
|
hasSpottedPlayer = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Turn(){
|
void Turn(){
|
||||||
|
IsPlayerNear();
|
||||||
|
if (!hasSpottedPlayer){
|
||||||
int direction = Random.Range(0, 4);
|
int direction = Random.Range(0, 4);
|
||||||
if (direction == 0 && map.CanMoveTo(Vector2Int.left)){
|
if (direction == 0 && map.CanMoveTo(Vector2Int.left)){
|
||||||
transform.Translate(Vector3.left);
|
transform.Translate(Vector3.left);
|
||||||
|
@ -37,4 +42,17 @@ public class Monster : MonoBehaviour
|
||||||
transform.Translate(Vector3.left);
|
transform.Translate(Vector3.left);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
//Put here pathfinding code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void IsPlayerNear(){
|
||||||
|
if ((player.transform.position.x-transform.position.x)<=3 || (transform.position.x-player.transform.position.x)>=-3){
|
||||||
|
hasSpottedPlayer=true;
|
||||||
|
}
|
||||||
|
if ((player.transform.position.y-transform.position.y)<=3 || (transform.position.y-player.transform.position.y)>=-3){
|
||||||
|
hasSpottedPlayer=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 19c0d85909aede34bb371863f187b9e0
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
Loading…
Reference in a new issue