[英]C# script unity 2d creating a clone Error CS0165
here is my code below the problem i think is the if statement below input.getaxis vertical这是我在问题下方的代码,我认为是 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;
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); }
//-----------------------------------------------------------------------------
}
in Unity3d when you create a GameObject like this在 Unity3d 中创建这样的 GameObject 时
GameObject projectile = null;
you can't assign it to anything in editor and there for because your GameObject remains null your getting error when you instantiate it.你不能将它分配给编辑器中的任何东西,因为你的游戏对象在你实例化它时仍然为空你得到错误。 use this code instead
改用此代码
public GameObject projectile = null;
now you must assign this GameObject in the Editor to what ever you want to instantiate.现在您必须将编辑器中的这个游戏对象分配给您想要实例化的内容。
UPDATE更新
and i noticed you instantate a null GameObject and put it in a GameObject with the Exact name!!我注意到你实例化了一个空的 GameObject 并将它放在一个具有确切名称的 GameObject 中!! of course you can get conflict from that change the second GameObject name.
当然,您可以从更改第二个游戏对象名称中获得冲突。 i think you need to learn more about Instantiate functionhere is a description for it.
我认为你需要了解更多关于 Instantiate 函数的信息,这里是它的描述。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.