所以我有这个脚本,我试图让一个立方体跳转到某个位置,其中一部分是我希望立方体在向新的Rich Point移动时播放动画,我有以下脚本但由于某些原因,动画不会变短或变长为什么?我做错了什么?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public float jumpMaxDistance;
public float jumpSpeed;
private float distance;
private bool firstFrame = false;
private Vector3 richPoint;
public GameObject player;
private Animation jump;
void Start () {
richPoint = transform.position;
jump = player.GetComponent<Animation> ();
}
// Update is called once per frame
void Update (){
//Moves the player to the next point.
if (firstFrame == true){
if (transform.position != richPoint) {
transform.position = Vector3.MoveTowards(transform.position, richPoint, Time.deltaTime * jumpSpeed);
}//executes if the left click is pressed.
}
if (Input.GetMouseButtonDown (0)) {
RaycastHit hit;
//Get Ray from mouse position.
Ray rayCast = Camera.main.ScreenPointToRay (Input.mousePosition);
//Raycast and check if any object is hit.
if (Physics.Raycast (rayCast, out hit, jumpMaxDistance))
{
//Raycast and check if any object is hit.
if (hit.collider.CompareTag ("RichPoint"))
{
richPoint = hit.collider.transform.position;
//This finds the distance between the player and richPoint.
float pBTime;
pBTime = distance / jumpSpeed;
//This plays the Animation depending on tha distance between transform.position and richPoint.
jump ["PlayerJump"].time = pBTime;
jump.Play ();
firstFrame = true;
}
}
}
}
}