[英]I cannot assign a script to my prefab in Unity
I have been trying to get my prefab as soon as it is instantiated to assign this script but I have looked around a lot and I have only been getting some vague answers this following script is on the prefab:我一直试图在实例化分配此脚本后立即获取我的预制件,但我环顾四周,只得到一些模糊的答案,以下脚本位于预制件上:
public float speed;
public float lifeTime;
public float distance;
public ShootingMechanic ShootScript;
public LayerMask whatIsSolid;
private void Start()
{
ShootScript = GameObject.Find("gun").GetComponent<ShootingMechanic>();
Invoke("DestroyProjectile", lifeTime);
}
void DestroyProjectile()
{
//Instantiate(DestroyEffect, transform.position, Quaternion.identity);
Destroy(gameObject);
}
public void Update()
{
transform.Translate(Vector2.up * speed * Time.deltaTime);
RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, transform.up, distance, whatIsSolid);
if(hitInfo.collider != null)
{
if (hitInfo.collider.CompareTag("Enemy"))
{
DestroyProjectile();
hitInfo.collider.GetComponent<Enemy>().TakeDamage(ShootScript.damagePerShot);
}
}
}
the only place your intantiate something in your givin script is in the Destroyed method, and even there it is //commented.在 givin 脚本中你 intantiate 的唯一地方是在 Destroyed 方法中,即使在那里它也是//注释的。 Feel free to delete this question
随意删除这个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.