子弹发射代码:
using UnityEngine;
using System.Collections;
using System.Threading;
public class shoot : MonoBehaviour
{
void Start()
{
}
public class Stuff
{
public int bullets;
public int grenades;
public int rockets;
public Stuff(int bul, int gre, int roc)
{
bullets = bul;
grenades = gre;
rockets = roc;
}
}
public Stuff myStuff = new Stuff(10, 7, 25);
public float speed;
public float turnSpeed;
public Rigidbody bulletPrefab;
public Transform firePosition;
public float bulletSpeed;
void Update ()
{
Movement();
Shoot();
bulletSpeed = 40f;
}
void Movement ()
{
float forwardMovement = Input.GetAxis("Vertical") * speed * Time.deltaTime;
float turnMovement = Input.GetAxis("Horizontal") * turnSpeed * Time.deltaTime;
transform.Translate(
网页链接 * forwardMovement);
transform.Rotate(
网页链接 * turnMovement);
}
void Shoot ()
{
if(Input.GetButtonDown("Fire1") &&
网页链接 > 0)
{
Rigidbody bulletInstance = Instantiate(bulletPrefab, firePosition.position, firePosition.rotation) as Rigidbody;
bulletInstance.AddForce(
网页链接 * bulletSpeed);
myStuff.bullets--;
}
}
}