Created
November 30, 2019 09:41
-
-
Save IshidaGames/4232043a8837f31b95a9804809f83129 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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