게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
유니티 버튼으로 캐릭터 움직이는것 관련해서 질문드립니다 ㅠ
게시물ID : programmer_20080짧은주소 복사하기
작성자 : 줄무늬니삭스
추천 : 0
조회수 : 942회
댓글수 : 5개
등록시간 : 2017/03/26 22:14:50
옵션
  • 창작글
  • 베스트금지
  • 베오베금지
  • 본인삭제금지
  • 외부펌금지
게임개발이 취미인 고3 학생입니다

다름이 아니라 유티니 모바일게임을 만들고 있습니다.
캡처.PNG

위와같은 게임인데요. 현재 문제인 부분인 키보드를 통해서는 좌,우,점프 가 전부 되지만 버튼을 통해서는 어떠한 이벤트도 먹히지 않습니다.

제 나름대로 공부도 하고 인터넷에서 코드도 조금 가져와서 만져보았지만 어떻게 해도 버튼을 이용한 캐릭터 움직임이 구현되지 않네요 ㅠㅠ

onclick을 이용해봤지만 역시 안됬습니다...
제 코드에 이상한점이 있는지 봐주셨으면 감사하겠습니다.

--------------------------------------------------------------------------------------------------------------------------

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

public class Player : MonoBehaviour {

   
    public float movePower = 1f;
    public Vector2 jumpPower;

    Rigidbody2D rigid;
   
    Vector3 movement;
    bool isJumping = false;
    bool collision_box = true;
    private Animator animator;
    private Collider2D mCollider2D;



    void Start()
    {
       
        rigid = gameObject.GetComponent<Rigidbody2D>();
        animator = gameObject.GetComponentInChildren<Animator>();
        mCollider2D = GetComponent<Collider2D>();
    }


    private void Update()
    {

        if (Input.GetAxisRaw("Horizontal") == 0)
        {
            animator.SetBool("isMoving", false);
        }
        else if (Input.GetAxisRaw("Horizontal") < 0)
        {
            animator.SetInteger("Direcion", -1); //왼쪽 플립
            animator.SetBool("isMoving", true);
        }
        else if (Input.GetAxisRaw("Horizontal") > 0)
        {
            animator.SetInteger("Direcion", 1); //오른쪽 플립
            animator.SetBool("isMoving", true);
        }

        if (Input.GetButtonDown("Jump") && collision_box)
        {
            transform.GetComponent<Rigidbody2D>().AddForce(jumpPower, ForceMode2D.Impulse);

        }

      

    }


  
    void FixedUpdate()
    {
       
        LeftButton();
        RightButton();
       
    }

   
    public void LeftButton()
    {
        Vector3 moveVelocity = Vector3.zero;
        if (Input.GetAxisRaw("Horizontal") < 0)
        {
            moveVelocity = Vector3.left;
            transform.localScale = new Vector3(-3.3f, 3.5f, 1);


        }
        transform.position += moveVelocity * movePower * Time.deltaTime;
    }

    public void RightButton()
    {
        Vector3 moveVelocity = Vector3.zero;
        if (Input.GetAxisRaw("Horizontal") > 0)
        {
            moveVelocity = Vector3.right;
            transform.localScale = new Vector3(3.3f, 3.5f, 1);


        }
        transform.position += moveVelocity * movePower * Time.deltaTime;
    }

 
}



꼬릿말 보기
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호