弾を撃つ

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

public class fire : MonoBehaviour
{
	public GameObject Tama;

	// Start is called before the first frame update
	void Start()
	{
	}

	// Update is called once per frame
	void Update()
	{
		if (Input.GetButtonDown("Fire1")) {
			//オブジェクトの作成
			GameObject Obj = Instantiate(Tama);
			//座標を合わせる
			Obj.transform.position = gameObject.transform.position;
			//向きをあわせる
			Obj.transform.forward = gameObject.transform.forward;
			//リジットボディの取得
			Rigidbody rb = Obj.GetComponent<Rigidbody>();
			//吹き飛ばす
			rb.AddForce(transform.forward * 50.0f, ForceMode.Impulse);
			//自動で消す
			Destroy(Obj, 5.0f);
		}
	}
}