Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unity3d 我不知道';我看不出实例化预置的脚本有什么问题_Unity3d - Fatal编程技术网

Unity3d 我不知道';我看不出实例化预置的脚本有什么问题

Unity3d 我不知道';我看不出实例化预置的脚本有什么问题,unity3d,Unity3d,我看不出这个代码有什么问题。它说变量projectleenemy没有分配给任何东西,尽管我打算通过inspector窗口为它分配预置,但是inspector窗口不会更新,因为有一个错误 using System.Collections; using System.Collections.Generic; using UnityEngine; public class Attack : MonoBehaviour { public Transform

我看不出这个代码有什么问题。它说变量projectleenemy没有分配给任何东西,尽管我打算通过inspector窗口为它分配预置,但是inspector窗口不会更新,因为有一个错误

   using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class Attack : MonoBehaviour {
        public Transform playerPos = null;
        private float playerDist;
        public GameObject projectileEnemy = null;

        private void Shoot()
        {
            GameObject projectileEnemy = Instantiate(projectileEnemy, transform.position, Quaternion.identity) as GameObject;
        }




        void Update () {
            playerDist = playerPos.position.x - transform.position.x;

            if (playerDist <= (3) && playerDist >= (-3))

            {
                Shoot();

                if (playerDist < (0))
                {
                    projectileEnemy.GetComponent<Rigidbody>().AddForce(transform.left * 10);
                }
                else
                {
                    projectileEnemy.GetComponent<Rigidbody>().AddForce(transform.right * 10);
                }
            }

        }
    }
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
公共类攻击:单一行为{
public Transform playerPos=null;
私人游戏者;
公共游戏对象projectleenemy=null;
私人射击()
{
GameObject ProjectleEnmy=实例化(ProjectleEnmy、transform.position、Quaternion.identity)为GameObject;
}
无效更新(){
playerDist=playerPos.position.x-transform.position.x;
如果(playerList=(-3))
{
射击();
如果(播放列表<(0))
{
projectleenemy.GetComponent().AddForce(transform.left*10);
}
其他的
{
projectleenemy.GetComponent().AddForce(transform.right*10);
}
}
}
}

你必须区分你创建的投射物(克隆物)和你用来复制的投射物(预制物)

//Assin在检查者中检查射弹的预制件
公共游戏对象projectleenemyprefab;
私有游戏对象投射克隆;
私人射击()
{
//克隆预制件以创建将被推进的敌人的真实投射物
projecteleclone=实例化(projectleenemyprefab,transform.position,Quaternion.identity)作为游戏对象;
}
无效更新(){
playerDist=playerPos.position.x-transform.position.x;
如果(playerList=(-3))
{
射击();
如果(播放列表<(0))
{
//推进实例化的**克隆**
projecteleclone.GetComponent().AddForce(transform.left*10);
}
其他的
{
//推进实例化的**克隆**
projecteleclone.GetComponent().AddForce(transform.right*10);
}
}
}

你必须区分你创建的投射物(克隆物)和你用来复制的投射物(预制物)

//Assin在检查者中检查射弹的预制件
公共游戏对象projectleenemyprefab;
私有游戏对象投射克隆;
私人射击()
{
//克隆预制件以创建将被推进的敌人的真实投射物
projecteleclone=实例化(projectleenemyprefab,transform.position,Quaternion.identity)作为游戏对象;
}
无效更新(){
playerDist=playerPos.position.x-transform.position.x;
如果(playerList=(-3))
{
射击();
如果(播放列表<(0))
{
//推进实例化的**克隆**
projecteleclone.GetComponent().AddForce(transform.left*10);
}
其他的
{
//推进实例化的**克隆**
projecteleclone.GetComponent().AddForce(transform.right*10);
}
}
}
// Assin in the inspector the prefab of the projectile
public GameObject projectileEnemyPrefab ;

private GameObject projectileClone ;

private void Shoot()
{
   // Clone the prefab to create the real projectile of the enemy which will be propelled
    projectileClone = Instantiate(projectileEnemyPrefab , transform.position, Quaternion.identity) as GameObject;
}

void Update () {
    playerDist = playerPos.position.x - transform.position.x;

    if (playerDist <= (3) && playerDist >= (-3))

    {
        Shoot();

        if (playerDist < (0))
        {

            // Propel the instantiated **clone**
            projectileClone .GetComponent<Rigidbody>().AddForce(transform.left * 10);
        }
        else
        {
            // Propel the instantiated **clone**
            projectileClone .GetComponent<Rigidbody>().AddForce(transform.right * 10);
        }
    }

}