
最近unity2dで横スクロールアクションを勉強していて
今移動するなどのアニメーションを動かそうとしています
しかし待機状態から移動するときのアニメーションに移行するスクリプトがうまくいきません
誰か教えてください
error CS0411: The type arguments for method `UnityEngine.Component.GetComponent<T>()' cannot be inferred from the usage. Try specifying the type arguments explicitlyというエラーが出ます
プログラムはこんな感じです
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Rigidbody2D))]
[RequireComponent(typeof(BoxCollider2D))]
public class UnityChanController : MonoBehaviour {
public Rigidbody2D cRigidbody2D
{
get
{
if(!_cRigidbody2D)
_cRigidbody2D = rigidbody2D;
return _cRigidbody2D;
}
}
Rigidbody2D _cRigidbody2D;
public Transform cTransform
{
get
{
if(!_cTransform)
_cTransform = transform;
return _cTransform;
}
}
Transform _cTransform;
public Animator cAnimator
{
get
{
if(!_cAnimator)
_cAnimator = GetComponent();
return _cAnimator;
}
}
Animator _cAnimator;
public float moveSpeed = 5;
public float jumpForce = 1000;
float InputHorValue;
bool isGrounded;
bool canJump;
void Update()
{
MecCheck();
InputCheck();
}
void InputCheck()
{
InputHorValue = Input.GetAxisRaw("Horizontal");
if(isGrounded && Input.GetButtonDown("Jump")) canJump = true;
}
void MecCheck()
{
bool isRunning = InputHorValue != 0;
cAnimator.SetBool("isRunning",isRunning);
}
void FixedUpdate()
{
Move();
Jump();
}
void Move()
{
if((cTransform.localScale.x > 0 && InputHorValue < 0)
|| (cTransform.localScale.x < 0 && InputHorValue > 0))
{
Vector2 temp = cTransform.localScale;
temp.x *= -1;
cTransform.localScale = temp;
}
cRigidbody2D.velocity = new Vector2(moveSpeed * InputHorValue,
cRigidbody2D.velocity.y);
}
void Jump()
{
if(canJump)
{
canJump = false;
isGrounded = false;
cRigidbody2D.AddForce(Vector2.up * jumpForce);
}
}
void OnCollisionEnter2D(Collision2D col)
{
if(col.gameObject.tag == "Ground")
isGrounded = true;
}
}
No.2ベストアンサー
- 回答日時:
~~~~~~~~~~
public Animator cAnimator
{
get
{
if(!_cAnimator)
_cAnimator = GetComponent();
return _cAnimator;
}
}
Animator _cAnimator;
~~~~~~~~~~
↓
~~~~~~~~~~
public Animator cAnimator
{
get
{
if(!_cAnimator)
_cAnimator = GetComponent<Animator>();
return _cAnimator;
}
}
Animator _cAnimator;
~~~~~~~~~~
こうするといいかも!?
No.3
- 回答日時:
ざっと見ただけですが、GetComponentの総称型にクラスを指定する、ということでは。
_cAnimator = GetComponent();
↓
_cAnimator = GetComponent<Animator>();
他にもプロパティでチェックしているフラグ変数はどうなっているのかとか、プロパティはいつ初期化されてるのかとか、不明なところがあるので動かしてはいませんが……。
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
C#でのWNetAddConnection3の使...
-
C# DataGridView列カスタマイズ
-
C#で別のFormへ複数の値を返そ...
-
C# visibleプロパティをfalseに...
-
JSPファイルから、ActionFormの...
-
パスがとおらない・・・
-
ORA-01858: 数値を指定する箇所...
-
C言語のポインターに関する警告
-
0dの意味を教えてください
-
オブジェクトの中のプロパティ...
-
ダブルクォーテーションを含む...
-
JSPやサーブレットでSystem.out...
-
System.err. printlnとSystem.o...
-
csv出力について
-
ダブルクォーテーションのrepla...
-
nullcline
-
Formの値が変更されたかどうか...
-
tomcatのstdout.logを停止したい。
-
文字コード変換
-
IF関数でEmpty値を設定する方法。
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
大量のデータを読み込んで表示...
-
Junitテストでvoid戻り値メッソ...
-
C#でキーイベントが発生しない...
-
ボタンの複数割り当てについて
-
C#で、あるクラスのメンバーす...
-
C#から、C++で作成したdll内の...
-
C# WinForm のDataGridView Cel...
-
C#でのWNetAddConnection3の使...
-
C# 親フォームで指定した値を...
-
C# 矢印キーの取得
-
unityでのC++エラーの原因がわ...
-
C# DataGridView列カスタマイズ
-
コンボボックスを使う時の警告
-
C#で、定数をフラグ(if文)に...
-
C# MouseHoverを何度も呼ぶには
-
C#で別のFormへ複数の値を返そ...
-
正規表現
-
【Java】画像表示が出来ない!
-
C# visibleプロパティをfalseに...
-
JavaのSwingで別のフォーム...
おすすめ情報