Ability to Restart Level, Player Spawning and a Test Level added + Bug Fix
This commit is contained in:
parent
7939328be7
commit
cc479e14ba
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 195a574a43515b84da3e006bc1890628
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -109,7 +109,7 @@ GameObject:
|
|||
- component: {fileID: 7008207192594766308}
|
||||
m_Layer: 6
|
||||
m_Name: Player
|
||||
m_TagString: Untagged
|
||||
m_TagString: Player
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
File diff suppressed because it is too large
Load Diff
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -40,5 +40,8 @@ namespace Level
|
|||
gameObject.SetActive(false);
|
||||
needsRestart = false;
|
||||
}
|
||||
|
||||
[ContextMenu("Restart")]
|
||||
public void Restart() => LevelManager.Instance.SwitchToLevel(LevelName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue