前提・実現したいこと
風船が地面から跳ね返って見えるようにして、画面の下部から離れないようにしたいです。
また地面のタグが足りるように調整したいです。
ご教示いただければ幸いです。
発生している問題・エラーメッセージ
Tag: Ground is not defined.
UnityEngine.GameObject:CompareTag(String)
PlayerControllerX:OnCollisionEnter(Collision) (at Assets/Challenge 3/Scripts/PlayerControllerX.cs:59)
該当のソースコード
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerControllerX : MonoBehaviour
{
public float maxHeight=18.0f;
private bool isLowEnough = true;
public bool gameOver;
public float floatForce; private float gravityModifier = 1.5f; private Rigidbody playerRb; public ParticleSystem explosionParticle; public ParticleSystem fireworksParticle; private AudioSource playerAudio; public AudioClip moneySound; public AudioClip explodeSound; // Start is called before the first frame update void Start() { Physics.gravity *= gravityModifier; playerAudio = GetComponent<AudioSource>(); playerRb=GetComponent<Rigidbody>(); // Apply a small upward force at the start of the game playerRb.AddForce(Vector3.up * 5, ForceMode.Impulse); } // Update is called once per frame void Update() { //高さ制限の判定 // float ht=gameObject.transform.position.y; //Debug.Log("Playerの高さ:"+ht); // While space is pressed and player is low enough, float up if(ht<maxHeight){ isLowEnough=true; } else{ isLowEnough=false; } if (Input.GetKey(KeyCode.Space) && !gameOver&&isLowEnough) { playerRb.AddForce(Vector3.up * floatForce); } } private void OnCollisionEnter(Collision other) { // if player collides with bomb, explode and set gameOver to true if (other.gameObject.CompareTag("Bomb")) { explosionParticle.Play(); playerAudio.PlayOneShot(explodeSound, 1.0f); gameOver = true; Debug.Log("Game Over!"); Destroy(other.gameObject); } else if(other.gameObject.CompareTag("Ground") && !gameOver) { } // if player collides with money, fireworks else if (other.gameObject.CompareTag("Money")) { fireworksParticle.Play(); playerAudio.PlayOneShot(moneySound, 1.0f); Destroy(other.gameObject); } }
}
試したこと
else if(other.gameObject.CompareTag("Ground") && !gameOver)入れました。
あなたの回答
tips
プレビュー