add sound to platform and repair deleting and edit jump and move

This commit is contained in:
haitem
2022-01-30 03:17:17 +01:00
parent dbe10318e1
commit 6f71f6225e
35 changed files with 723 additions and 37 deletions

View File

@@ -7,6 +7,8 @@ public class PlatformManager : MonoBehaviour
public enum PlatformType {Basic, Pull, Push, RotateZ, RotateY, SpeedUp, SpeedDown};
public PlatformType type = PlatformType.Pull;
public float speed = 5;
public AudioSource audioSource;
public List<AudioClip> audioClips = new List<AudioClip>();
void FixedUpdate()
{
@@ -17,4 +19,12 @@ public class PlatformManager : MonoBehaviour
transform.Rotate(transform.up * speed * Time.deltaTime);
}
}
public void Step()
{
if (audioSource != null && audioClips.Count > 0 && !audioSource.isPlaying)
{
audioSource.PlayOneShot(audioClips[Random.Range(0, audioClips.Count)]);
}
}
}

View File

@@ -85,7 +85,7 @@ public class PlayerController : MonoBehaviour
}
float curSpeedX = canMove ? (currentSpeed + speedModifier) : 0;
float curSpeedY = canMove ? (currentSpeed + 3.5f + speedModifier) * Input.GetAxis("Horizontal") : 0;
float curSpeedY = canMove ? (currentSpeed + 5f + speedModifier) * Input.GetAxis("Horizontal") : 0;
moveDirection = (platformForward * curSpeedX * Time.deltaTime) + (transform.right * curSpeedY * Time.deltaTime);
@@ -105,7 +105,7 @@ public class PlayerController : MonoBehaviour
}
if (audioSource != null && audioClips.Count > 0) {
if ((currentSpeed + speedModifier) > speed * 3f && (currentSpeed + speedModifier) < speed * 7f)
if ((currentSpeed + speedModifier) > speed * 3f && (currentSpeed + speedModifier) < speed * 6f)
{
if (audioClips.Count > 1 && audioSource.clip != audioClips[1]) {
audioSource.Stop();
@@ -118,7 +118,7 @@ public class PlayerController : MonoBehaviour
audioSource.clip = audioClips[0];
audioSource.Play();
}
} else if ((currentSpeed + speedModifier) >= speed * 7f) {
} else if ((currentSpeed + speedModifier) >= speed * 6f) {
if (audioClips.Count > 2 && audioSource.clip != audioClips[2])
{
audioSource.Stop();
@@ -136,7 +136,7 @@ public class PlayerController : MonoBehaviour
if (inAir)
{
// Debug.Log("Jump");
rb.AddForce(transform.up * jumpSpeed * 100 * Time.deltaTime, ForceMode.Impulse);
rb.AddForce(transform.up * jumpSpeed * 100f * Time.deltaTime, ForceMode.Impulse);
inAir = false;
}
@@ -219,10 +219,10 @@ public class PlayerController : MonoBehaviour
if (other.GetContact(0).normal == other.transform.forward
|| other.GetContact(0).normal == -other.transform.forward
|| other.GetContact(0).normal == -other.transform.right
|| other.GetContact(0).normal == other.transform.right
|| (other.GetContact(0).normal != -other.transform.up
&& other.GetContact(0).normal != other.transform.up
&& other.GetContact(0).normal != other.transform.right
&& other.GetContact(0).normal != -other.transform.right)
&& other.GetContact(0).normal != other.transform.up)
)
{
return;
@@ -240,24 +240,10 @@ public class PlayerController : MonoBehaviour
isGrounded = true;
if (other.gameObject.tag == "platform")
{
if (other.GetContact(0).normal == other.transform.forward
|| other.GetContact(0).normal == -other.transform.forward
|| (other.GetContact(0).normal != -other.transform.up
&& other.GetContact(0).normal != other.transform.up
&& other.GetContact(0).normal != other.transform.right
&& other.GetContact(0).normal != -other.transform.right)
)
{
return;
}
saveDirection = -other.GetContact(0).normal;
Vector3 gDirection = -other.GetContact(0).normal;
PlatformManager platform = other.gameObject.GetComponent<PlatformManager>();
if (platform != null)
{
platform.Step();
switch (platform.type)
{
case PlatformManager.PlatformType.Push:
@@ -285,14 +271,24 @@ public class PlayerController : MonoBehaviour
speedModifier = 0.0f;
}
break;
default:
gDirection = -other.GetContact(0).normal;
break;
}
}
else
if (other.GetContact(0).normal == other.transform.forward
|| other.GetContact(0).normal == -other.transform.forward
|| other.GetContact(0).normal == -other.transform.right
|| other.GetContact(0).normal == other.transform.right
|| (other.GetContact(0).normal != -other.transform.up
&& other.GetContact(0).normal != other.transform.up)
)
{
gDirection = -transform.up;
return;
}
Vector3 gDirection = -other.GetContact(0).normal;
saveDirection = gDirection;
if (platform == null)
{
gDirection = -other.GetContact(0).normal;
}
platformForward = other.transform.forward;
this.downDirection = gDirection;

View File

@@ -47,7 +47,7 @@ public class ProceduralGeneration : MonoBehaviour
List<GameObject> spawnSpiralOfPlatforms(GameObject lastObject, GameObject objToSpawn, GameObject parentLevelObject)
{
// configuration:
float horizontalDistancePerPlatform = (float)Random.Range(0.5f, 2.0f);
float horizontalDistancePerPlatform = (float)Random.Range(1.0f, 3.0f);
List<GameObject> levelBlocksSpawnTemp = new List<GameObject>();
// Debug.Log("Building LOOP");
@@ -102,7 +102,7 @@ public class ProceduralGeneration : MonoBehaviour
for (var i = 0; i < this.spawnedLevelBlocks.Count; i++)
{
float distance = Vector3.Distance(this.spawnedLevelBlocks[i].transform.position, playerPosition);
if (distance > this.maximumDistanceOfPlatformFromPlayer && this.spawnedLevelBlocks.Count >= this.maximumNumberOfPlatformsAtScene)
if (distance > this.maximumDistanceOfPlatformFromPlayer && this.spawnedLevelBlocks.Count >= this.maximumNumberOfPlatformsAtScene && playerPosition.z > this.spawnedLevelBlocks[i].transform.position.z)
{
Destroy(this.spawnedLevelBlocks[i]);
this.spawnedLevelBlocks.Remove(this.spawnedLevelBlocks[i]);