私は半作品のコードを書いています。すべてが作業アニメーションから離れて機能します。アニメーターをコライダーでプレイする(Unity3d/c#)
私がしようとしていることは、プレーヤーがトリガを入力し、彼/彼女がEを押すとアニメーションを実行することです。 (アニメーションはうまく動作していますので、コードエラーですか?)
は、ここで私はこれまで得たものです:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class barTrigger : MonoBehaviour {
// press shit to drink text
public GameObject drinkText;
// bottle
public GameObject alcBottle;
// drink animator
public GameObject animatorOjbect;
Animator drinkAmin;
public bool triggerIsOn;
// Use this for initialization
void Start() {
drinkAmin = animatorOjbect.GetComponent<Animator>();
drinkText.SetActive(false);
alcBottle.SetActive(false);
}
// Update is called once per frame
void Update() {
}
void OnTriggerEnter(Collider other){
triggerIsOn = true;
if (other.gameObject.name == "vThirdPersonController") {
drinkText.SetActive (true);
}
if (triggerIsOn && Input.GetKeyDown (KeyCode.E)) {
drinkAmin.Play ("Dab");
alcBottle.SetActive (true);
}
}
void OnTriggerExit(Collider other){
if (other.gameObject.name == "vThirdPersonController") {
drinkText.SetActive (false);
alcBottle.SetActive (false);
}
}
}
助けてください?
'Debug.Log'を使って' OnTriggerEnter'と 'OnTriggerExit'関数が呼び出されるようにします。 – Programmer
@Programmer duh。すでにテスト済みです。 – papi
私はあなたを助けることはできませんが、GameObjectのdrinkTextに関するコメントは素晴らしいです。私が提案できるベストは、OnTriggerEnterにブレークポイントを設定し、Eを押すとtriggerIsOnの値が何であるかを確認することです。ロジックに従って、別の場所にリセットされているかどうかを確認します。 – Brien