Skip to content

Instantly share code, notes, and snippets.

using UnityEngine;
public class MoveToPlayer : MonoBehaviour
{
public Transform player;
public float speed;
public float maxDistance;
void Update()
{
if (Vector3.Distance(player.position, transform.position) < maxDistance)
@modyari
modyari / Achievements.cs
Created January 2, 2022 19:15
An example of using events to implement an achievment system
public class Achievements : MonoBehaviour
{
//..More code here
private void Awake()
{
Item.OnCollectedItem += HandleItemCollected;
}
private void OnDestroy()
{
using System;
using System.Collections;
using UnityEngine;
namespace RoutineUtility
{
/// <summary>
/// A routine utility that tracks whether a routine is still active or not
/// </summary>
public class Routine
public void HandlePickup(GameCharacter character)
{
DeactivatePowerUp();
OnPickedUp?.Invoke(this, character);
}
@modyari
modyari / example1.cs
Last active January 25, 2023 23:17
Dependency rule article code snippets
public void HandlePickup()
{
DeactivatePowerUp();
hideAnimation.Play();
powerUpUI.Show()
soundManager.PlaySound(Sounds.PowerUp);
player.Pickup(this);
}
public void HandlePickup(GameCharacter character)
{
DeactivatePowerUp();
hideAnimation.Play();
if (character is Player)
{
powerUpUI.Show()
soundManager.PlaySound(Sounds.PowerUp);
}
else
@modyari
modyari / VectorExtensions.cs
Created September 13, 2021 16:14
(Unity) Modifies a Vector's component and returns it
using UnityEngine;
public static class VectorExtensions
{
/// <summary>
/// Returns a modified version of the vector with one or more components modified
/// </summary>
/// <param name="x">X component to modify</param>
/// <param name="y">Y component to modify</param>
/// <returns>A modified version of the vector with the passed component configurations</returns>