C#/수업 내용
과제 ninjastar <표창 날리기 게임>
Lewisjkim
2022. 1. 18. 10:52
목표 = 표창을 날리는 게임을 만들려고한다
표창 = 메이플스토리 표창의 이미지를 누끼따서 png 소스로 준비했다.
Action =
1. 마우스 클릭을 하는 지점부터 마우스 클릭을 때는 순간 거리까지의 y축 세로 길이에 비례하여 표창의 날라가는 속도를 정한다.(swipe)
2. 표창의 날라갈 때의 회전을 표현 하기 위해 회전을 걸어준다.
배경 = 잘보이는 보색 계열로 배경을 선택했다
주의할 점=
self는 로컬이고 world는 글로벌
코드 =
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NinjastarController : MonoBehaviour
{
float speed = 0;
float rotSpeed = 0;
Vector3 startPos;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//마우스를 누르면
if(Input.GetMouseButtonDown(0))//스와이프 하면 날라가는거
{
this.startPos = Input.mousePosition;//시작 지점 지정
}
//마우스를 때면
else if (Input.GetMouseButtonUp(0))
{
Vector3 endPos = Input.mousePosition;//종료 지점 지정
float swipelength = endPos.y - this.startPos.y;//스와이프렝스 정의
this.speed = (swipelength / 30.0f)*Time.deltaTime;//이동 속도 초기화
}
this.rotSpeed = 20;
transform.Rotate(new Vector3(0, 0, this.rotSpeed));
transform.Translate(new Vector3(0, this.speed,0),Space.World);//스피드
this.speed *= 0.98f;
}
}
실행화면=
실행 파일= 녹스 및 안드로이드에서 실행 가능