Download Link
Code Snippets
-
using System.Collections;
using UnityEngine;
public class IcePower : MonoBehaviour
{
public bool onCooldown1;
public bool onCooldown2;
public float cooldownTime = 10f;
public float stunnedTime = 3f;
public bool stunned1 = false;
public bool stunned2 = false;
[SerializeField] PlayerMovement player1;
[SerializeField] PlayerMovement2 player2;
[SerializeField] ParticleSystem ice1;
[SerializeField] ParticleSystem ice2;
[SerializeField] PlaceHandler placeHandler;
// Start is called before the first frame update
void Start()
{
}
public void Update()
{
if (Input.GetButtonDown("Grab") && onCooldown1 == false)
{
ice1.Play();
StartCoroutine(OnCooldown1());
StartCoroutine(Stunned1());
player1.Jump();
if (stunned1)
{
player1.movementSpeed = 0f;
}
}
if (!stunned1)
{
ice1.Stop();
player1.movementSpeed = 2f;
}
if (Input.GetButtonDown("Grab2") && onCooldown2 == false)
{
ice2.Play();
StartCoroutine(OnCooldown2());
StartCoroutine(Stunned2());
player2.Jump();
if (stunned2)
{
player2.movementSpeed = 0f;
}
}
if (!stunned2)
{
ice2.Stop();
player2.movementSpeed = 2f;
}
}
IEnumerator OnCooldown1()
{
onCooldown1 = true;
yield return new WaitForSeconds(cooldownTime);
onCooldown1 = false;
}
IEnumerator OnCooldown2()
{
onCooldown2 = true;
yield return new WaitForSeconds(cooldownTime);
onCooldown2 = false;
}
IEnumerator Stunned1()
{
stunned1 = true;
yield return new WaitForSeconds(stunnedTime);
stunned1 = false;
}
IEnumerator Stunned2()
{
stunned2 = true;
yield return new WaitForSeconds(stunnedTime);
stunned2 = false;
}
}
-
using UnityEngine;
public class WaypointFollower : MonoBehaviour
{
[SerializeField] GameObject[] waypoints;
int currentWaypointIndex = 0;
[SerializeField] float speed = 1f;
void Update()
{
if (Vector3.Distance(transform.position, waypoints[currentWaypointIndex].transform.position) < .1f)
{
currentWaypointIndex++;
if (currentWaypointIndex >= waypoints.Length)
{
currentWaypointIndex = 0;
}
}
transform.position = Vector3.MoveTowards(transform.position, waypoints[currentWaypointIndex].transform.position, speed * Time.deltaTime);
}
}