2017-10-30 28 views
-1

생존 게임을 만들고 있습니다 ... 저는 약간의 움직임을 만들었지 만 지금은 캐릭터가 점프하여 플랫폼 위에 올라서 호이스트를 시작하고 시작하려고합니다. 그 플랫폼에서 걷고 ... 그리고 나는 수영하기를 원한다. 나는 젤다 호흡기에서 수영을하는 것을 보았다. 모터 스크립트내 플레이어가 단결로 수영하고 움켜 잡고 호이스트로 만들기

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

public class Jump : MonoBehaviour { 
private CharacterController jumpControl; 
private float gravity = 7f, jumpForce = 5f; 
private float verticalVelocity; 
NavMeshAgent agent; 
PlayerMotor motor; 

// Use this for initialization 
void Start() { 
    jumpControl = GetComponentInChildren<CharacterController>(); 
    agent = GetComponentInParent<NavMeshAgent>(); 
} 

// Update is called once per frame 
void FixedUpdate() { 

    if (jumpControl.isGrounded) { 
     verticalVelocity = -gravity * Time.deltaTime; 
     agent.enabled = true; 


     if (Input.GetMouseButtonDown (1)) { 
      agent.enabled = false; 
      verticalVelocity = jumpForce; 
      Vector3 moveVector = new Vector3 (0, verticalVelocity, 0); 
      jumpControl.Move (moveVector * Time.deltaTime); 
     } 

    } else { 
     verticalVelocity -= gravity * Time.deltaTime; 
     Vector3 moveVector = new Vector3 (0, verticalVelocity, 0); 
     jumpControl.Move (moveVector * Time.deltaTime); 
    } 

} 

}

다음 :

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

[RequireComponent(typeof(NavMeshAgent))] 
public class PlayerMotor : MonoBehaviour { 

Transform target; 
public NavMeshAgent agent; 
// Use this for initialization 
void Start() { 
    agent = GetComponent<NavMeshAgent>(); 

} 
void Update(){ 
    if (target != null) { 
     agent.SetDestination (target.position); 
     FaceTarget(); 
    } 
} 

public void MoveToPoint(Vector3 point){ 
    agent.SetDestination (point); 
} 

public void FollowTarget(Interactables newTarget){ 
    agent.stoppingDistance = newTarget.radius * .8f; 
    agent.updateRotation = false; 
    target = newTarget.interactionTransform; 
} 

public void StopFollowingTarget(){ 
    agent.stoppingDistance = 0f; 
    agent.updateRotation = true; 
    target = null; 

} 
void FaceTarget(){ 
    Vector3 direction = (target.position - 
transform.position).normalized; 
    Quaternion lookRotation = Quaternion.LookRotation (new Vector3 
(direction.x, 0, direction.z)); 
    transform.rotation = Quaternion.Slerp (transform.rotation, 
lookRotation, Time.deltaTime * 5f); 
} 
} 

답변

0

1) 먼저 다운로드 animations.You 할 수있는 몇 가지 수영 나는이 내 점프 스크립트입니다

을 도움이 필요하세요 일부는 here에서 가져 오십시오.

2)이 애니메이션을 캐릭터의 애니메이션 컨트롤러에 추가하십시오. 애니메이션을 인간형으로 변경해야합니다 (기본값은 입니다).

3) 필요할 때마다 애니메이션을 트리거하십시오.

Myanimator.SetTrigger("animation trigger name"); 

4)의 선택을 취소 애니메이션 컨트롤러에서 "루트 모션을 적용"이동하려는 어느 방향으로 속도를 추가 할 수 있습니다. 일부 정지 또는 애니메이션을 상승 및 플랫폼의 양쪽에 트리거를 추가하고 OnTriggerEnter()

에이 애니메이션을 호출하기위한 또 점프 잡아 기능 검색을 추가 할 수

yourRigidBody.velocity = new Vector3 (0, yourRigidBody.velocity.y, speed); 

5)