반응형
SMALL
각종 setup
- https://www.pixilart.com/draw# 를 이용하여 톤앤 매너 맞추기
- 사용중인 스프라이트 반전기능 & 스프라이트 필터
- 부분 저장기능
- 유니티 스프라이트 옵션
우측 아날로그 터치패드
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class SpcialWeapon : MonoBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler
{
public GameObject gun;
public Animator playeranimi;
public GameObject[] hands;
public RectTransform lever;
private RectTransform rectTransform;
[SerializeField, Range(10f, 150f)]
private float leverRange;
private Vector2 inputVector;
public void Start()
{
this.rectTransform = GetComponent<RectTransform>();
}
public void OnBeginDrag(PointerEventData eventData)
{
this.ControlJoystickLever(eventData);
}
public void OnDrag(PointerEventData eventData)
{
this.ControlJoystickLever(eventData);
}
public void OnEndDrag(PointerEventData eventData)
{
this.lever.anchoredPosition = Vector2.zero;
}
public void ControlJoystickLever(PointerEventData eventData)
{
Vector2 inputDir = eventData.position - rectTransform.anchoredPosition;
Vector2 clampedDir = inputDir.magnitude < leverRange ? inputDir
: inputDir.normalized * leverRange;
this.lever.anchoredPosition = clampedDir;
this.inputVector = clampedDir;
}
public void GunRotate(Vector2 dir)
{
this.gun.transform.right = dir;
}
void Update()
{
if (Input.GetMouseButton(0))
{
this.GunRotate(inputVector);
}
Debug.Log(this.inputVector);
if (this.inputVector.x < 0)
{
this.gun.GetComponent<SpriteRenderer>().flipY = true;
//for(int i = 0; i < 2; i++) hands[i].GetComponent<SpriteRenderer>().flipY = true;
}
else
{
this.gun.GetComponent<SpriteRenderer>().flipY = false;
//for (int i = 0; i < 2; i++) hands[i].GetComponent<SpriteRenderer>().flipY = false;
}
if (this.inputVector.x < 45f && this.inputVector.x > -45f && this.inputVector.y > 0)
{
this.gun.GetComponent<SpriteRenderer>().sortingOrder = -2;
for (int i = 0; i < 2; i++) hands[i].GetComponent<SpriteRenderer>().sortingOrder = -1;
}
else { this.gun.GetComponent<SpriteRenderer>().sortingOrder = 0;
for (int i = 0; i < 2; i++) hands[i].GetComponent<SpriteRenderer>().sortingOrder = 1;
}
if(this.inputVector.x < 40f && this.inputVector.x > -40f && this.inputVector.y < 0)
{
this.playeranimi.SetInteger("temp", 0);
}
if(this.inputVector.y < 30f && this.inputVector.y > -30f && this.inputVector.x < 0)
{
this.playeranimi.SetInteger("temp", 3);
}
if (this.inputVector.x < 40f && this.inputVector.x > -40f && this.inputVector.y > 0)
{
this.playeranimi.SetInteger("temp", 1);
}
if (this.inputVector.y < 40f && this.inputVector.y > -40f && this.inputVector.x > 0)
{
this.playeranimi.SetInteger("temp", 2);
}
}
}
반응형
LIST
'프로젝트 > 건즈앤 레이첼스' 카테고리의 다른 글
[프로젝트] 스프라이트 배경 라인 따기 & 스프라이트 슬라이스 문제 (0) | 2023.03.01 |
---|---|
[프로젝트] 오브젝트 주위를 도는 오브젝트 (Rotate Arround) (0) | 2023.03.01 |
[유니티] 게임 진입 구조잡기 - as연산자, 비동기식 데이터 로드 (0) | 2023.02.27 |
[유니티] 대쉬 (회피) 기능 고민 (0) | 2023.02.26 |
[유니티] 터치 아날로드 패드를 이용한 무기 회전 (0) | 2023.02.26 |