Merge remote-tracking branch 'origin/Syntriax' into Over

This commit is contained in:
OverflowNarhoym
2022-02-25 14:06:49 +01:00
23 changed files with 1903 additions and 1361 deletions

View File

@@ -21,7 +21,7 @@ namespace AI
protected bool isShooting = false;
protected IMovement movement = null;
protected bool canShoot => (target.transform.position - transform.position).sqrMagnitude < attackRangeSquared && target != null;
protected bool canShoot => target != null && (target.transform.position - transform.position).sqrMagnitude < attackRangeSquared;
public UnityEvent OnShoot { get; protected set; } = null;
@@ -36,11 +36,13 @@ namespace AI
cooldownPerShoot = 1f / attacksPerSecond;
attackRangeSquared = attackRange * attackRange;
OnShoot = new UnityEvent();
UpdateTarget(FindObjectOfType<Player.PlayerController>()?.transform);
}
protected virtual void Start()
=> movement = transform.GetComponentInParent<IMovement>();
{
movement = transform.GetComponentInParent<IMovement>();
UpdateTarget(FindObjectOfType<Player.PlayerController>()?.transform);
}
protected virtual void Update()
{

View File

@@ -40,5 +40,8 @@ namespace Level
gameObject.SetActive(false);
needsRestart = false;
}
[ContextMenu("Restart")]
public void Restart() => LevelManager.Instance.SwitchToLevel(LevelName);
}
}

View File

@@ -46,6 +46,8 @@ namespace Level
Destroy(this);
}
public GameObject Player { get; private set; } = null;
private void Initialize()
{
GameObject[] levelPrefabs = Resources.LoadAll<GameObject>("Levels/");
@@ -64,6 +66,11 @@ namespace Level
level.SetLevel(levelPrefab.name);
_levels.Add(levelPrefab.gameObject.name, level);
}
Player = GameObject.FindWithTag("Player");
if (Player == null)
Player = (GameObject)Instantiate(Resources.Load("Playable/Player"), transform.position, Quaternion.identity);
Player.SetActive(false);
}
public void SwitchToLevel(string levelName)
@@ -73,13 +80,16 @@ namespace Level
currentLevel = Levels[levelName];
currentLevel.Enable();
// TODO Move Player To currentLevel.StartingPoint
Player.SetActive(true);
Player.transform.position = currentLevel.StartingPoint.position;
Player.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
UIManager.Instance.CloseAllCanvases();
}
private void DisableAllLevels()
{
Player.SetActive(false);
foreach (Level level in Levels.Values)
level.Disable();
}