Initial commit
This commit is contained in:
101
Assets/Scripts/PlatformScripts/Platform.cs
Normal file
101
Assets/Scripts/PlatformScripts/Platform.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using NUnit.Framework;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
public class Platform : MonoBehaviour, IPlatform
|
||||
{
|
||||
[SerializeField] private List<GameObject> _platformPiece = new List<GameObject>();
|
||||
[SerializeField] private Material _safeMaterial;
|
||||
[SerializeField] private Material _deathMaterial;
|
||||
|
||||
public List<GameObject> platformPiece => _platformPiece;
|
||||
public Material safeMaterial => _safeMaterial;
|
||||
public Material deathMaterial => _deathMaterial;
|
||||
|
||||
private IPlatformRule _platformRule;
|
||||
private bool hasAchievedScore = false;
|
||||
|
||||
[Inject] Player player;
|
||||
[Inject] IPool pool;
|
||||
[Inject] IPlatformManager platformManager;
|
||||
[Inject] ScoreService scoreService;
|
||||
|
||||
|
||||
public void SetPlatformRule(IPlatformRule platformRule)
|
||||
{
|
||||
_platformRule = platformRule;
|
||||
_platformRule.Execute(this);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if(other.CompareTag("Player") && !hasAchievedScore)
|
||||
{
|
||||
hasAchievedScore = true;
|
||||
Debug.Log("Score Increased");
|
||||
scoreService.AddScore();
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (player.transform.position.y < transform.position.y-5f)
|
||||
{
|
||||
hasAchievedScore = false;
|
||||
pool.ReturnToPool(this);
|
||||
platformManager.BuildNewPlatform();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public interface IPlatform
|
||||
{
|
||||
List<GameObject> platformPiece { get; }
|
||||
Material safeMaterial { get; }
|
||||
Material deathMaterial { get; }
|
||||
}
|
||||
|
||||
|
||||
public interface IPlatformRule
|
||||
{
|
||||
public void Execute(IPlatform platform);
|
||||
}
|
||||
|
||||
public class FirstPlatform : IPlatformRule
|
||||
{
|
||||
public void Execute(IPlatform platform)
|
||||
{
|
||||
foreach(var piece in platform.platformPiece)
|
||||
{
|
||||
piece.SetActive(true);
|
||||
piece.GetComponent<Renderer>().material = platform.safeMaterial;
|
||||
piece.tag = "Safe";
|
||||
}
|
||||
platform.platformPiece[Random.Range(1,platform.platformPiece.Count)].gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public class OtherPlatform : IPlatformRule
|
||||
{
|
||||
int danger = 2;
|
||||
public void Execute(IPlatform platform)
|
||||
{
|
||||
foreach (var piece in platform.platformPiece)
|
||||
{
|
||||
piece.SetActive(true);
|
||||
piece.GetComponent<Renderer>().material = platform.safeMaterial;
|
||||
piece.tag = "Safe";
|
||||
}
|
||||
|
||||
for (int i=0;i<danger;i++)
|
||||
{
|
||||
GameObject deadPlatform = platform.platformPiece[Random.Range(0, platform.platformPiece.Count)];
|
||||
deadPlatform.GetComponent<Renderer>().material = platform.deathMaterial;
|
||||
deadPlatform.tag = "Death";
|
||||
}
|
||||
platform.platformPiece[Random.Range(0, platform.platformPiece.Count)].gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user