Skip to content

Instantly share code, notes, and snippets.

@IshidaGames
Created November 30, 2019 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IshidaGames/4232043a8837f31b95a9804809f83129 to your computer and use it in GitHub Desktop.
Save IshidaGames/4232043a8837f31b95a9804809f83129 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PresentFire : MonoBehaviour
{
//発射したいオブジェクトを入れる
public GameObject present;
Rigidbody rb;
//発射したい位置に置いた空のオブジェクトを入れる
public GameObject shotPos;
void Update()
{
//左クリックで設定したオブジェクトを生成し発射
if (Input.GetMouseButtonDown(0))
{
//設定したオブジェクトを生成
GameObject copy = Instantiate(present, shotPos.transform.position,
Quaternion.identity);
//生成したオブジェクトのRigidbodyを取得
rb = copy.GetComponent<Rigidbody>();
//Rigidbodyに力を加えて飛ばす
rb.AddForce(transform.forward * 1000 + transform.up * 1000);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment