This commit is contained in:
haitem 2022-01-29 21:04:09 +01:00
commit 1064957555
2 changed files with 42 additions and 29 deletions

View File

@ -66,12 +66,16 @@ public class PlayerController : MonoBehaviour
currentSpeed += 0.0005f;
}
if (Input.GetAxis("Vertical") > 0 && currentSpeed < maxSpeed) {
if (!canMove) {
if (Input.GetAxis("Vertical") > 0 && currentSpeed < maxSpeed)
{
if (!canMove)
{
canMove = true;
}
currentSpeed += 0.01f;
} else if (Input.GetAxis("Vertical") < 0 && currentSpeed > minSpeed) {
}
else if (Input.GetAxis("Vertical") < 0 && currentSpeed > minSpeed)
{
currentSpeed -= 0.01f;
}
@ -222,9 +226,12 @@ public class PlayerController : MonoBehaviour
modifier += platform.speed;
break;
case PlatformManager.PlatformType.SpeedDown:
if (modifier - platform.speed >= 0) {
if (modifier - platform.speed >= 0)
{
modifier -= platform.speed;
} else {
}
else
{
modifier = 0.0f;
}
break;
@ -232,8 +239,10 @@ public class PlayerController : MonoBehaviour
gDirection = -other.GetContact(0).normal;
break;
}
} else {
gDirection = -other.GetContact(0).normal;
}
else
{
gDirection = -transform.up;
}
platformForward = other.transform.forward;
this.downDirection = gDirection;

View File

@ -10,13 +10,22 @@ public class ProceduralGeneration : MonoBehaviour
public GameObject lastBlock;
private GameObject lastBlockPrefab;
private int spavnetobjectIndex = 0;
private int maximumNumberOfPlatformsAtScene = 100;
private float maximumDistanceOfPlatformFromPlayer = 20.0f;
// Start is called before the first frame update
void Start()
GameObject drawPlatform(GameObject lastObject, GameObject objToSpawn)
{
lastBlockPrefab = this.gameObject.transform.GetChild(0).gameObject;
lastBlock = this.gameObject.transform.GetChild(0).gameObject;
this.spawnedLevelBlocks.Add(lastBlock);
MeshFilter meshfilter = lastObject.GetComponent<MeshFilter>();
Bounds bounds = meshfilter.mesh.bounds;
float scale = meshfilter.transform.localScale.x;
Bounds b = new Bounds(bounds.center * scale, bounds.size * scale);
Vector3 nextBlockLocation = new Vector3(lastObject.transform.position.x, lastObject.transform.position.y, lastObject.transform.position.z + b.size.z + 1.0f);
return Instantiate(objToSpawn, nextBlockLocation, (Quaternion.identity));
}
List<GameObject> spawnSpiralOfPlatforms(GameObject lastObject, GameObject objToSpawn)
@ -53,19 +62,23 @@ public class ProceduralGeneration : MonoBehaviour
return levelBlocksSpawnTemp;
}
// Start is called before the first frame update
void Start()
{
lastBlockPrefab = this.gameObject.transform.GetChild(0).gameObject;
lastBlock = this.gameObject.transform.GetChild(0).gameObject;
this.spawnedLevelBlocks.Add(lastBlock);
}
// Update is called once per frame
void Update()
{
int maxNumberOfBlock = 200;
Vector3 playerPosition = this.player.transform.position;
Debug.Log("Index" + 0);
for (var i = 0; i < this.spawnedLevelBlocks.Count; i++)
{
float distance = Vector3.Distance(this.spawnedLevelBlocks[i].transform.position, playerPosition);
if (distance > 10.0f && this.spawnedLevelBlocks.Count >= maxNumberOfBlock)
if (distance > this.maximumDistanceOfPlatformFromPlayer && this.spawnedLevelBlocks.Count >= this.maximumNumberOfPlatformsAtScene)
{
Destroy(this.spawnedLevelBlocks[i]);
this.spawnedLevelBlocks.Remove(this.spawnedLevelBlocks[i]);
@ -78,7 +91,7 @@ public class ProceduralGeneration : MonoBehaviour
}
if (this.spawnedLevelBlocks.Count <= maxNumberOfBlock)
if (this.spawnedLevelBlocks.Count <= this.maximumNumberOfPlatformsAtScene)
{
int blockToSpawn = Random.Range(0, levelBlocks.Count);
@ -97,15 +110,7 @@ public class ProceduralGeneration : MonoBehaviour
if ((blockToSpawn > -1 && (blockToSpawn < (levelBlocks.Count - 1))))
{
MeshFilter meshfilter = this.lastBlock.GetComponent<MeshFilter>();
Bounds bounds = meshfilter.mesh.bounds;
float scale = meshfilter.transform.localScale.x;
Bounds b = new Bounds(bounds.center * scale, bounds.size * scale);
blockObjToSpawn = levelBlocks[blockToSpawn];
Vector3 nextBlockLocation = new Vector3(this.lastBlock.transform.position.x, this.lastBlock.transform.position.y, this.lastBlock.transform.position.z + b.size.z + 1.0f);
instantiatedGameObject = Instantiate(blockObjToSpawn, nextBlockLocation, (Quaternion.identity));
instantiatedGameObject = this.drawPlatform(this.lastBlock, this.levelBlocks[blockToSpawn]);
this.spawnedLevelBlocks.Add(instantiatedGameObject);
}
@ -120,7 +125,6 @@ public class ProceduralGeneration : MonoBehaviour
blockObjToSpawn = levelBlocks[0];
}
Debug.Log("Spawn" + blockToSpawn);
this.lastBlock = instantiatedGameObject;
this.lastBlockPrefab = blockObjToSpawn;