Unityについてです。
下記の警告が出ていてスクリプトが正常に動作しないのですがどうすればいいでしょうか。
原因はコードだと思われますが、どこが悪いのかがわかりません。
警告文
There are inconsistent line endings in the 'Assets/Attack.cs' script. Some are Mac OS X (UNIX) and some are Windows.
This might lead to incorrect line numbers in stacktraces and compiler errors. Many text editors can fix this using Convert Line Endings menu commands.
日本語
'Assets / Attack.cs'スクリプトに矛盾する行末があります。 Mac OS X(UNIX)もあればWindowsもあります。
これにより、スタックトレースの不正な行番号やコンパイラエラーが発生する可能性があります。多くのテキストエディタは、行末変換メニューコマンドを使用してこれを修正できます。
動かないスクリプト
ゲームのアイコンのオブジェクトにアタッチされています。
表示非表示を切り替えたり、クリックされた動作をBattleManagerに送る役割をしています。
開始時に、Debug.Log"AA""dd"が2回ずつ出ます。なのでスクリプトは動いてます。でもAAが二回出るはずがないのでおかしいです。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Attack : MonoBehaviour
{
GameObject BattleManagger;
BattleManager sc;
int BNsyori = 0;//scから変数の変化によって処理をするのを重複させない役割 void Start() { Debug.Log("AA"); BattleManagger = GameObject.Find("BattleManagger"); sc = BattleManagger.GetComponent<BattleManager>(); } // Update is called once per frame void Update() { int BsyoriA = sc.BsyoriA; int BsyoriB = sc.BsyoriB; int Inputo = sc.Inputo; if (BsyoriA == 1 && BNsyori == 0) { BNsyori = 1; StartCoroutine("hyouzi"); } if (Inputo == 1 && BNsyori == 1) { BNsyori = 2; StartCoroutine("hihyouzi"); } } public IEnumerator hihyouzi() { Debug.Log("dd"); transform.position = new Vector2(-6, -4); for (float f = 0; f < 16; f++) { transform.Translate(new Vector2(0, -0.125f)); yield return new WaitForSeconds(0.02f); } } public IEnumerator hyouzi() { Debug.Log("dd"); transform.position = new Vector2(-6f, -6); for (float f = 0; f < 16; f++) { transform.Translate(new Vector2(0, 0.125f)); yield return new WaitForSeconds(0.02f); } BNsyori = 0; } void OnMouseOver() { if (Input.GetMouseButtonDown(0) && BNsyori == 0) { BNsyori = 1; sc.Attack(); } }
}
ちなみに、同じような動作をするオブジェクトがもう一つあって、それのスクリプト(下記)は正常に動きます。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bunseki : MonoBehaviour
{
GameObject BattleManagger;
BattleManager script;
int BNsyori = 0; void Start() { BattleManagger = GameObject.Find("BattleManagger"); script = BattleManagger.GetComponent<BattleManager>(); } // Update is called once per frame void Update() { int BsyoriA = script.BsyoriA; int BsyoriB = script.BsyoriB; int Inputo = script.Inputo; if (BsyoriA == 1 && BNsyori == 0) { BNsyori = 1; script.BsyoriAsyori(); StartCoroutine("hyouzi"); } if (Inputo == 1 && BNsyori == 1) { BNsyori = 2; StartCoroutine("hihyouzi"); } } public IEnumerator hihyouzi() { transform.position = new Vector2(1.3f, -4); for (float f = 0; f < 16; f++) { transform.Translate(new Vector2(0, -0.125f)); yield return new WaitForSeconds(0.02f); } } public IEnumerator hyouzi() { transform.position = new Vector2(1.3f, -6); for (float f = 0; f < 16; f++) { transform.Translate(new Vector2(0, 0.125f)); yield return new WaitForSeconds(0.02f); } BNsyori = 0; } void OnMouseOver() { if (Input.GetMouseButtonDown(0) && BNsyori == 0) { BNsyori = 1; script.Bunseki(); } }
}
BattleManager (必要そうな部分だけ)
public class BattleManager : MonoBehaviour
{
public int Z = 0;
public int flee = 0;//自由に使って良い変数
public Text messagewindow;
public static int PlayerLV;
public int BsyoriA;
public int BsyoriB;
public int m_syori = 0;
//略
public void BsyoriAsyori() { BsyoriA += 1; } public void Bunseki() { MsgB = 1; Inputo = 1; StartCoroutine("Bunsekii"); } public void Attack() { MsgB = 1; Inputo = 1; StartCoroutine("Attackk"); } public void MsgBa() { MsgB = 1; }
説明やコードが理解しがたかったらすみません。抽象的な事でもいいので、警告文やスクリプトが動かない理由として考えられること、手がかりがあれば教えていただけると嬉しいです。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/04 04:54
2019/04/04 05:20
2019/04/04 06:59