-
-
Save ppengotsu/bc973de80b48d380098de9c95f756290 to your computer and use it in GitHub Desktop.
ARDKのブログ2のボール飛ばすコード
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 ActionManager : MonoBehaviour | |
{ | |
[SerializeField] | |
private GameObject ballPrefab; | |
[SerializeField] | |
private Camera mainCamera; | |
void Start() | |
{ | |
} | |
void Update() | |
{ | |
#if UNITY_EDITOR | |
// | |
// UnityEditorで動かしてるとき | |
// | |
if(Input.GetMouseButtonDown(0)){ | |
// | |
// 画面がクリックされた時の処理 | |
// | |
FireBall(); | |
} | |
#else | |
// | |
// ビルドして実機で動かしてるとき | |
// | |
if(Input.touchCount>0){ | |
Touch touch0 = Input.GetTouch(0); | |
if(touch0.phase == TouchPhase.Began){ | |
// | |
// 画面がタッチされた時の処理 | |
// | |
FireBall(); | |
} | |
} | |
#endif | |
} | |
/// <summary> | |
/// ボールオブジェクトを生成して飛ばします。 | |
/// </summary> | |
private void FireBall(){ | |
float power = 2.0f;//ボールを飛ばす強さ | |
GameObject ballObject = GameObject.Instantiate(ballPrefab, mainCamera.transform.position, Quaternion.identity); | |
ballObject.GetComponent<Rigidbody>().AddForce(mainCamera.transform.forward* power); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment