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