【发布时间】:2017-06-22 16:25:23
【问题描述】:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Gun : MonoBehaviour {
public int Player_Health = 100;
public GameObject Player;
public Rigidbody Bullet;
public Transform Guun;
public bool Player_Dead = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.Space))
{
Rigidbody rocketInstance;
rocketInstance = Instantiate(Bullet, Guun.position, Guun.rotation) as Rigidbody;
rocketInstance.AddForce(Guun.forward * 5000);
}
if(Player_Health == 0)
{
Player_Dead = true;
}
if(Player_Dead == true)
{
Destroy(Player);
}
}
private void OnCollisionEnter(Collision col)
{
if(col.gameObject.name == "Player")
{
Player_Health = Player_Health - 20;
Debug.Log(Player_Health);
}
}
}
1.因此,当我通过按空格进行实例化时,它首先实例化 1,然后是 2,然后是 4,然后是 8,依此类推——为什么每次按下时不实例化 1。 我想在这里制造一把枪,显然需要它一次只能发射一颗子弹,因为目前它可以发射多发。正如我已经解释过的那样,它首先会发射一颗子弹,然后下次发射时会加倍,依此类推。
【问题讨论】:
-
请将您的两个问题作为单独的问题发布(因此您的问题过于宽泛)。
-
@cybermonkey 他们是非常简单的问题请至少回答一个
-
你的第二个问题没有意义。请解释一下或将其作为一个 enw 问题提出。
-
这不是这个网站的运作方式。如果它们是简单的问题并不重要,它们需要在不同的问答中。
-
@Programmer 你能回答第一个吗
标签: c# unity3d clone instantiation