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

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

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

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

Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

Q&A

解決済

1回答

1765閲覧

getcomponentについて

yuuki_yui_

総合スコア14

C#

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

Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

0グッド

0クリップ

投稿2018/12/25 05:24

unity 2018 2.7で3Dゲームを本を参照しながら作っています。
以下のエラーが出ます

error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement ```C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BasketController : MonoBehaviour
{
public AudioClip appleSE;
public AudioClip bombSE;
AudioSource aud;
GameObject director;

void Start(){ this.director = GameObject.Find("GameDirector"); this.aud = GetComponent<AudioSource>(); } //タグを表示、アイテムを破棄 void OnTriggerEnter(Collider other){ if(other.gameObject.tag == "Apple"){ this.director.GetComponent<GameDirector>().GetApple; this.aud.PlayOneShot(this.appleSE); } else { this.director.GetComponent<GameDirector>().GetBomb; this.aud.PlayOneShot(this.bombSE); } Destroy(other.gameObject); } // Update is called once per frame void Update() { if(Input.GetMouseButtonDown(0)){ Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { float x = Mathf.RoundToInt(hit.point.x); float z = Mathf.RoundToInt(hit.point.z); transform.position = new Vector3(x, 0, z); } } }

}

this director.GetComponent<GameDirector>().GetApple; this director.GetComponent<GameDirector>().GetBomb; においてメソッドの参照をしていますが上のようなエラーが出ます。 getapple,getbombは他のスクリプトで以下のように書いています。 ```C# using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class GameDirector : MonoBehaviour { GameObject timerText; GameObject pointText; float time = 60; int point = 0; //りんごをキャッチした時のポイント public void GetApple() { this.point += 100; } //爆弾をキャッチした時のポイント public void GetBomb() { this.point /= 2; }

様々なサイトを見て見ましたが解決方法がわかりません。
ご教授お願いします。

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

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

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

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

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

guest

回答1

0

ベストアンサー

こんにちは。

メソッド呼び出しには()が必須です。
this.director.GetComponent<GameDirector>().GetApple();で、「引数なしのメソッドを実行」という意味です。

投稿2018/12/25 05:32

tamoto

総合スコア4103

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

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

yuuki_yui_

2019/05/27 06:34

返信がとても遅くなってしまい、申し訳ございません。 ( )を見落としていました、とても初歩的なミスの回答をありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問