728x90
728x90
Addforce를 활용한 게임 요소 구현하기 충격력(Force) : 질량 * 거리 / 시간^2 충격량(Impulse) : 질량 * 거리 / 시간 using System.Collections; using System.Collections.Generic; using UnityEngine; public class ForceController : MonoBehaviour { private Rigidbody boxRigidbody; private float movePower = 5f; void Start() { boxRigidbody = GetComponent(); } private void FixedUpdate() { //Impulse는 1초동안 가해진 힘의 합 //FixedUpdate의 경우 0.02초동안 스..
유니티 행렬과 이동의 관계 using System.Collections; using System.Collections.Generic; using UnityEngine; //게임에서 행렬을 사용하는 경우는 DirectX, OpenGL, 유니티에서는 shader 심화과정에 주로 사용 public class Matrix : MonoBehaviour { private Matrix4x4 worldMat; void Start() { MakeWorldMatrix(); ExtractionMatrix(); } void MakeWorldMatrix() { Quaternion rot = Quaternion.Euler(45, 0, 45); //회전행렬 이용(오일러 각 : 직관적으로 각도를 이용한 것) //오일러 공식을 사용하..
벡터의 외적을 활용한 게임 요소 구현 using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class WarriorController : MonoBehaviour { private Rigidbody2D warriorRigidbody2D; public float jumpPower; public float speed; void Start() { warriorRigidbody2D = GetComponent(); } void Update() { PlayerMove(); PlayerJump(); } void PlayerMove() { float x = Input.GetAxis("Horizo..
백터의 내적을 활용한 게임 요소 구현 using System.Collections; using System.Collections.Generic; using UnityEngine; using Vector2 = System.Numerics.Vector2; public class FlashController : MonoBehaviour { public GameObject[] ghostObjectArray; public float moveSpeed = 3f; public float rangeAngle = 25f; public float rangeDistance = 4f; void Update() { PlayerMove(); CheckGhost(); } void PlayerMove() { float x = Inp..
삼각함수를 사용하여 오브젝트 이동 방법 총알 발사 패턴 using System.Collections; using System.Collections.Generic; using UnityEngine; // 1. Player 이동 2. Player 이동 패턴을 원을 그리며 이동 3. 미사일 발사(순차적) 4. 미사일 발사(한번에) public enum Pattern { One, Two }; public class PlayerController : MonoBehaviour { public GameObject bulletObject; public Transform bulletContainer; public Pattern shotPattern; // 패턴을 선택할 수 있게 되어 있음 public float move..
다형성 - virtual, override - 객체 지향의 핵심 - 함수의 오버라이딩(재정의) - 반복문으로 객체 관리 - virtual과 override 키워드 사용 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _083_override { class Super { protected int num; public virtual void Print() { Console.WriteLine("num : {0}", num); } } class AA : Super { public int a; public override void Prin..