0
所以我有這個腳本,我試圖讓一個立方體跳到某個位置,其中一部分是我希望立方體在向新的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;
}
}
}
}
}