私はバスケットボールの試合をしていますが、そこではタイマーが切れた後ボールがあなたの手の中に戻され、デフォルトの位置は再び撮影する。私は0,0,0に戻って回転するようにプレーヤーを得ることができません。 (これは私の最初のゲームです。私はちょっと羽ばたきましたので、私のコードの残りは恐ろしいものですが、学習経験であるので建設的な批評は大歓迎です)再作成時にプレーヤーを0,0,0に戻すことができません
私のコード...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour {
public Ball ball;
public GameObject playerCamera;
public float ballDistance = 2f;
public float ballThrowingForce = 5f;
public float powerTimer = 0f;
public bool holdingBall = true;
public Player player;
public float resetTimer = 5f;
// Use this for initialization
void Start() {
ball.GetComponent<Rigidbody>().useGravity = false;
}
// Update is called once per frame
void Update()
{
if (holdingBall) {
{
ball.transform.position = playerCamera.transform.position + playerCamera.transform.forward * ballDistance;
}
if (Input.GetMouseButton (0)) {
if (powerTimer == 10) {
powerTimer = 10;
} else if (powerTimer < 10) {
powerTimer = powerTimer + Time.deltaTime;
ballThrowingForce = ballThrowingForce + 2 * powerTimer;
}
}
}
if (holdingBall) {
if (Input.GetMouseButtonUp (0)) {
holdingBall = false;
ball.GetComponent<Rigidbody>().useGravity = true;
ball.GetComponent<Rigidbody>().AddForce (playerCamera.transform.position + playerCamera.transform.forward * ballThrowingForce);
}
}
if (player.holdingBall == false) {
resetTimer -= Time.deltaTime;
if (resetTimer <= 0) {
player.transform.position = new Vector3 (-0.2427547f, 2.6f, -2.357f);
// player roation to 0,0,0 here
holdingBall = true;
ball.GetComponent<Rigidbody>().useGravity = false;
powerTimer = 0;
ballThrowingForce = 400;
resetTimer = 5;
}
if (Input.GetKeyDown (KeyCode.Return)) {
resetTimer = 0;
}
}
}
}
10時にはタイマーを止めてくれてありがとう、私はまだスローのパワーを微調整する必要があります。何らかの理由でplayer.transformer.rotation = Quaternion.identityが機能しません。 –
申し訳ありません 'player.transform.rotation = Quaternion.identity'、私はタイプミスをしました:( – fazega