วันศุกร์ที่ 2 ธันวาคม พ.ศ. 2559

Shooting โค้ดยิงกระสุนนน



using UnityEngine;
using System.Collections;

public class Shootiing : MonoBehaviour {

public GameObject bulletPrefab;
public float bulletImpulse = 100.0f;

public GameObject CameraObject;
// Use this for initialization
void Start () {

}

public void FireOut()
{
GameObject theBullet = (GameObject)Instantiate (bulletPrefab , CameraObject.transform.position , CameraObject.transform.rotation);
theBullet.GetComponent<Rigidbody> ().AddForce ( CameraObject.transform.forward * bulletImpulse , ForceMode.Impulse);
}

public void NotFireOut()
{

}

// Update is called once per frame
void Update () {
if(Input.GetButtonDown("Fire1"))
{
FireOut ();
}
}
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น