C# C脚本unity 2d创建克隆错误CS0165
下面是我的代码,我想问题是input.getaxis vertical下面的if语句C# C脚本unity 2d创建克隆错误CS0165,c#,unity3d,unityscript,C#,Unity3d,Unityscript,下面是我的代码,我想问题是input.getaxis vertical下面的if语句 using UnityEngine; using System.Collections; public class moveit : MonoBehaviour { private Collectable shoot; private static int ammun; public static bool defense; public arrow Arrow;
using UnityEngine;
using System.Collections;
public class moveit : MonoBehaviour {
private Collectable shoot;
private static int ammun;
public static bool defense;
public arrow Arrow;
public float Speed = 1f;
private float movex = 0f;
private float movey = 0f;
public static Animator animator;
GameObject projectile = null;
// Use this for initialization
void Start () {
animator = GetComponent<Animator> ();
shoot = GetComponent<Collectable>();
}
// Update is called once per frame
void Update () {
ammun = Collectable.ammo;
// the movement and aanimation code----------------------
movex = Input.GetAxis ("Horizontal");
if (movex == 0f){
animator.SetInteger ("AnimState", 1);
}else if(movex == 1f){
animator.SetInteger ("AnimState", 2);
}else if(movex == -1f){
animator.SetInteger ("AnimState", 3);
}
movey = Input.GetAxis ("Vertical");
if(ammun == 1 && movey == -1){
GameObject projectile = Instantiate (projectile, new Vector3 (0, 0, 0), Quaternion.identity) as GameObject;
}
rigidbody2D.velocity = new Vector2 (movex * Speed, movey * Speed); }
//-----------------------------------------------------------------------------
}
在Unity3d中创建这样的游戏对象时
GameObject projectile = null;
您不能在编辑器中将其分配给任何对象,因为当您实例化它时,您的游戏对象仍然为空,您的获取错误仍然为空。请改用此代码
public GameObject projectile = null;
现在你必须在编辑器中将这个游戏对象分配给你想要实例化的对象
更新
我注意到你实例化了一个空的游戏对象,然后把它放在一个游戏对象中,并用它的确切名称!!当然,更改第二个游戏对象名称会导致冲突。
我认为您需要了解更多有关实例化函数的信息。实例化函数是对它的描述。请给出更多解释。你的代码有哪些功能?哪些不起作用?请写错误消息而不是代码名