LoginSignup
0
0

More than 5 years have passed since last update.

左クリックで弾を飛ばす※編集中

Posted at
Shooting.cs

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

public class Shooting : MonoBehaviour {


    public GameObject bullet;
    public Transform muzzle;
    public float speed = 1000;


    void Start()
    {

    }

    void Update()
    {

        if (Input.GetButtonDown("Fire1"))

        {
            StartCoroutine("shot");
                    }
    }
    IEnumerator shot()
    {
        GameObject bullets = GameObject.Instantiate(bullet) as GameObject;
        yield return new WaitForSeconds(0.5f);
        Vector3 force;
        force = this.gameObject.transform.forward * speed;
        bullets.GetComponent<Rigidbody>().AddForce(force);
        bullets.transform.position = muzzle.position;
            }
    }
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0