
IPointerClickHandler와 같은 인터페이스를 써야 되지 않을까 싶다Fire()를 넣는다. 그리고 만약 키보드 키와 겹칠 경우를 대비해서 마우스 클릭중이면 키보드 비활성화, 키보드 입력중이면 버튼 비활성화를 해야 한다Button 을 상속받는 컴포넌트를 만든다. Update()에서 키보드 입력중일 때는 버튼을 비활성화 한다public class ButtonController : Button
private void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
// 또는
this.SetActive(false);
}
if(Input.GetKeyUp(KeyCode.Space))
{
this.SetActive(true);
}
}Button 컴포넌트와 Selectable 인터페이스들을 찾아보면서 어떤 기능들이 가능한지 찾아보면 좋다.void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
PressAttack();
}
if (Input.GetKeyUp(KeyCode.C))
{
PressChangeMode();
}
}
public void PressAttack()
{
// 연사 공격
if (rapidCoroutine == null && fireMode == false)
{
rapidCoroutine = StartCoroutine(FireRoutine());
}
if (rapidCoroutine != null && fireMode == false)
{
StopCoroutine(rapidCoroutine);
rapidCoroutine = null;
// 차지 공격
if (fireMode == true)
{
if (chargeCoroutine == null)
{
chargeCoroutine = StartCoroutine(ChargeRoutine());
}
}
}
public void PressChangeMode()
{
// 공격 모드 전환 : C키
if (chargeCoroutine != null)
{
StopCoroutine(chargeCoroutine);
chargeCoroutine = null;
}
else if (rapidCoroutine != null)
{
StopCoroutine(rapidCoroutine);
rapidCoroutine = null;
}
ChangeFireForm();
}

score 텍스트를 만든다

score를 넣는다3~4번 내용은 UI 포스트에서 구현했다
Scale with screen size를 사용하면된다앵커를 사용한다




내 에셋에 추가하기를 누른다
유니티에서 열기 선택하면 위와 같은 화면이 나온다. Download를 누른다
Import하면 된다
Canvas로 드래그&드롭을 해서 추가했다플레이를 누르고 이리저리 조작해보았지만 움직이는 걸로 연결되지 않는다
public class JoystickPlayerExample : MonoBehaviour
{
public float speed;
public VariableJoystick variableJoystick;
public Rigidbody rb;
public void FixedUpdate()
{
Vector3 direction = Vector3.forward * variableJoystick.Vertical + Vector3.right * variableJoystick.Horizontal;
rb.AddForce(direction * speed * Time.fixedDeltaTime, ForceMode.VelocityChange);
}
}


Joystic으로 가본다
Horizontal과 Vertical, Vector2 Direction 이다//조이스틱 추가
[SerializeField] DynamicJoystick dynamicJoystick;
void Update()
{
TankMove();
TurretRotation();
}
private void TankMove()
{
// 조이스틱으로 받기
tankInput.x = dynamicJoystick.Horizontal;
tankInput.z = dynamicJoystick.Vertical;
if (tankInput == Vector3.zero)
{
return;
}
magnitude = tankInput.magnitude;
if (magnitude > 1f )
{
magnitude = 1f;
}
tankInput = tankInput.normalized;
transform.Translate(tankInput * magnitude * tankMoveSpeed * Time.deltaTime, Space.World);
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(tankInput), tankRotInterpolation);
}
Canvas에 만들어뒀던 조이스틱을 드래그&드롭하면 된다
