using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RefMain : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
int age = 10;
this.SayHello(age);
Debug.Log(age);
}
void SayHello(int num)
{
num = num + 40;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RefMain : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
int age = 10;
this.SayHello(ref age);
Debug.Log(age);
}
void SayHello(ref int num)
{
num = num + 40;
}
}
Ref를 사용하면 원본이 변한다.
변수 지정을 안하면 오류가 남
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RefMain : MonoBehaviour
{
[SerializeField]
private Transform startTrans;
[SerializeField]
private Transform endTrans;
[SerializeField]
private Transform playerTrans;
[SerializeField]
private float smoothTime = 1f;
[SerializeField]
private Transform offsetTrans;
private Vector3 velocity = Vector3.zero;
private void Update()
{
//반환값 : 보간된 위치
//this.playerTrans.position = Vector3.SmoothDamp(this.playerTrans.position, this.endTrans.position, ref velocity, this.smoothTime);
//Debug.Log(this.velocity);
}
private void OnDrawGizmos()
{
DrawArrow.ForGizmo(this.playerTrans.position, this.playerTrans.up);
}
}
방향벡터는 크기와 방향만 가지고있어서 위치는 중요하지않다.
위치벡터는 위치만 가지고 있으면 된다.
'유니티 심화' 카테고리의 다른 글
SpaceShooter2D - 스페이스바 눌러서 총쏘고 제거하기 [완] (0) | 2023.08.18 |
---|---|
챕터5 - 총알 (0) | 2023.08.18 |
Lerp, Slerp (0) | 2023.08.18 |
캐릭터 애니메이션 추가 (0) | 2023.08.18 |
절대강좌 유니티 - 카메라 distance, height 이동 (0) | 2023.08.18 |