Skip to content

Instantly share code, notes, and snippets.

Avatar
💻
Man At Work 🚜

Eduardo Pereira eduardonunesp

💻
Man At Work 🚜
View GitHub Profile
View side_collision.cs
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag.Equals("Wall"))
{
Vector3 hit = col.contacts[0].normal;
Debug.Log(hit);
float angle = Vector3.Angle(hit, Vector3.up);
if (Mathf.Approximately(angle, 0))
{
View mouse_click.cs
if (Input.GetMouseButtonDown(0))
{
Vector3 point = Camera.main.ScreenToWorldPoint(Input.mousePosition);
}
View weapon_follows_mouse.cs
using UnityEngine;
public class WeaponFollowsMouse : MonoBehaviour {
private void Update() {
Vector2 direction = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
Quaternion rotation = Quaternion.AngleAxis(angle - 90, Vector3.forward);
transform.rotation = rotation;
}
}
View loader.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Loader : MonoBehaviour
{
void Awake()
{
GameObject gameManager = GameObject.Find("GameManager");
View check_bounds_colliders.cs
Collider2D playerCollider2D = _playerOwner.GetComponent<Collider2D>();
Collider2D testableArea = _collider2D.GetComponent<Collider2D>();
if (testableArea.bounds.Contains(_playerOwner.transform.position)) {
// COLLIDES !
}
View raycast_2d.cs
using UnityEngine;
public class RayCast2DExample : MonoBehaviour
{
// Float a rigidbody object a set distance above a surface.
public float floatHeight; // Desired floating height.
public float liftForce; // Force to apply when lifting the rigidbody.
public float damping; // Force reduction proportional to speed (reduces bouncing).
View ways_of_rotate.cs
void Update() {
transform.eulerAngles = Vector3.forward * degrees;
// or
transform.rotation = Quaternion.Euler(Vector3.forward * degrees);
// or
transform.rotation = Quaternion.LookRotation(Vector3.forward, yAxisDirection);
// or
transform.LookAt(Vector3.forward, yAxisDirection);
// or
transform.right = xAxisDirection;
View camera_size.cs
void Start()
{
Camera cam = Camera.main;
float height = 2f * cam.orthographicSize;
float width = height * cam.aspect;
Debug.Log("Height: " + height);
Debug.Log("Width: " + width);
}
@eduardonunesp
eduardonunesp / move_towards_angle.cs
Created Sep 3, 2019
Move Towards Angle Facing Angle
View move_towards_angle.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : MonoBehaviour
{
public static GameManager Instance { get { return _instance; } }
private static GameManager _instance;
void Awake()
View singleton_pattern.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : MonoBehaviour
{
public static GameManager Instance { get { return _instance; } }
private static GameManager _instance;
void Awake()
You can’t perform that action at this time.