質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Q&A

0回答

1759閲覧

Unity 風船を地面のオブジェクトと衝突し衝突する際上向きの衝撃力を与えたいです

mai_70529

総合スコア0

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

0グッド

0クリップ

投稿2020/08/01 03:45

前提・実現したいこと

風船が地面から跳ね返って見えるようにして、画面の下部から離れないようにしたいです。
また地面のタグが足りるように調整したいです。
ご教示いただければ幸いです。

発生している問題・エラーメッセージ

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)入れました。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

stdio

2020/08/20 00:11

まだ答えを求めているかは分かりませんが、まずどこが出来ていないのか教えて頂けないでしょうか? 今回の場合、stepは2つあります。どちらが分からないのでしょうか? 1.風船と地面との衝突判定 2.風船に上向きの衝撃力を与える。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問