Skip to content

Instantly share code, notes, and snippets.

View InputExample.cs
//Using the new Unity input system,
// a simple code that takes the player animation from a walk to a run if the _axisInput.x is held for 2 seconds.
// Something like this non working code where speed > 3 is run and less than 3 is walk and 2f is time the input key is held down:
// YES, we are very new at this lol
if (_axisInput.x >= Time.deltaTime * 2f)
_animator.SetFloat("Speed", 3);
else
else _animator.SetFloat("Speed", -.02f);
View BladeTrap.cs
using UnityEngine;
public class BladeTrap : MonoBehaviour
{
private void OnCollisionEnter(Collision collision)
{
var enemy = collision.collider.GetComponentInParent<Enemy>();
if (enemy == null)
return;
View Perf.cs
using UnityEngine;
public class Perf : MonoBehaviour
{
[SerializeField] int _callsPerFrame = 10000;
void Update()
{
for (int i = 0; i < _callsPerFrame; i++)
{
View Bomb.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bomb : MonoBehaviour
{
[SerializeField] float _countdownTime = 5f;
[SerializeField] float _radius = 5f;
[SerializeField] int _damage = 5;
View rotate.cs
int nextY = 0;
int direction = 1;
private void Update()
{
if (nextY == 90 || nextY == 0)
direction *= -1;
nextY += direction;
var nextRotation = new Vector3(transform.rotation.eulerAngles.x, nextY, transform.rotation.eulerAngles.z);
transform.rotation = Quaternion.Euler(nextRotation);
View ParticleSpawner.cs
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
public class ParticleSpawner : MonoBehaviour
{
[SerializeField] private List<AssetReference> _particleReferences;
View StickToMovingObjects.cs
private void StickToMovingObjects()
{
if(groundedObj != null){
if(groundedObjLastPosition.HasValue &&
groundedObjLastPosition.Value != groundedObj.position){
//Determines the delta of the last position to the new position.
Vector3 delta = groundedObj.position - groundedObjLastPosition.Value;
//Moves the grounded object at the same rate as the groundedObj.
GetComponent<Rigidbody2D>().position += (Vector2)delta;
}
View program.cs
using System.IO;
namespace binarywritertest
{
class Program
{
static void Main(string[] args)
{
byte[] data = new byte[100];
for (byte i = 0; i < 100; i++)
View GameDataController.cs
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class GameDataController : MonoBehaviour
{
public static SaveData saveData;
private void Awake()
{
View ChromaCooldown.cs
using Corale.Colore.Core;
using Corale.Colore.Razer.Keyboard;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class ChromaCooldown : MonoBehaviour
{
public const float COOLDOWN_TIME = 4f;