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

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

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

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

Unity3D

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

Q&A

解決済

2回答

1486閲覧

初心者ですサイトをまねして作っていたらエラーが発生してしまいました。

Unityud

総合スコア10

C#

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

Unity3D

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

0グッド

0クリップ

投稿2019/08/10 23:47

編集2019/08/10 23:58

初心者なのでサイトをまねして作っていたら2つエラーが発生してしまいましたどうすればいいですか?
真似しているサイト→ (https://unity.moon-bear.com/zombie-slayer/gauge-and-score/)
エラーメッセージ↓
1つ目 The name"Shoot Timer"does not exist in the current context
2つ目 The name"GetInput"does not exist in the current context

バージョンunity 2019 2.1
コード↓
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class FirstPersonGunController : MonoBehaviour
{
public enum ShootMode { AUTO, SEMIAUTO }

public bool shootEnabled = true; [SerializeField] ShootMode shootMode = ShootMode.AUTO; [SerializeField] int maxAmmo = 100; [SerializeField] int maxSupplyValue = 100; [SerializeField] int damage = 1; [SerializeField] float shootInterval = 0.1f; [SerializeField] float shootRange = 50; [SerializeField] float supplyInterval = 0.1f; [SerializeField] Vector3 muzzleFlashScale; [SerializeField] GameObject muzzleFlashPrefab; [SerializeField] GameObject hitEffectPrefab; [SerializeField] Image ammoGauge; [SerializeField] Text ammoText; [SerializeField] Image supplyGauge; bool shooting = false; bool supplying = false; int ammo = 0; int supplyValue = 0; GameObject muzzleFlash; GameObject hitEffect; public int Ammo { set { ammo = Mathf.Clamp(value, 0, maxAmmo); //UIの表示を操作 //テキスト ammoText.text = ammo.ToString("D3"); //ゲージ float scaleX = (float)ammo / maxAmmo; ammoGauge.rectTransform.localScale = new Vector3(scaleX, 1, 1); } get { return ammo; } } public int SupplyValue { set { supplyValue = Mathf.Clamp(value, 0, maxSupplyValue); if (SupplyValue >= maxSupplyValue) { Ammo = maxAmmo; supplyValue = 0; } float scaleX = (float)supplyValue / maxSupplyValue; supplyGauge.rectTransform.localScale = new Vector3(scaleX, 1, 1); } get { return supplyValue; } } void Start() { InitGun(); } void Update() { if (shootEnabled & ammo > 0 & GetInput()) //ここの行 { StartCoroutine(ShootTimer()); //ここの行 } if (shootEnabled) { StartCoroutine(SupplyTimer()); } }0. public void InitGun() { Ammo = maxAmmo; SupplyValue = 0; } //--中略-- IEnumerator SupplyTimer()> { if (!supplying) { supplying = true; SupplyValue++; yield return new WaitForSeconds(supplyInterval); supplying = false; } }

}

できればどこが間違っていたのかを教えてください。

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

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

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

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

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

m.ts10806

2019/08/10 23:51

>バージョンunity 2019 2.1 タグに「Unity」があるので追加しておいてください。
guest

回答2

0

そうしたら前回作ったFirstPersonGunControllerを変更して、このスクリプトからゲージを操作するようにします。スクリプトを全部載せると長いし変更点が分かりづらいので適当に省略しておきますね。

最初からやってください。

投稿2019/08/10 23:53

Zuishin

総合スコア28656

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

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

0

ベストアンサー

1つ目 The name"Shoot Timer"does not exist in the current context
2つ目 The name"GetInput"does not exist in the current context

Shoot TimerメソッドとGetInputメソッドが書かれていないことが原因です。

以下のページで解説されていますね。

弾の発射処理の作り方&エフェクトの追加方法
https://unity.moon-bear.com/zombie-slayer/shoot-and-effect/

投稿2019/08/11 01:47

nskydiving

総合スコア6500

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

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

Unityud

2019/08/11 09:47

出来ましたありがとうございます!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問