質問編集履歴
1
変数名を修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -75,7 +75,7 @@
|
|
75
75
|
using System.Collections.Generic;
|
76
76
|
using UnityEngine;
|
77
77
|
|
78
|
-
public class
|
78
|
+
public class BallController : MonoBehaviour
|
79
79
|
{
|
80
80
|
private Rigidbody _rigidBody;
|
81
81
|
|
@@ -101,18 +101,18 @@
|
|
101
101
|
using System.Collections.Generic;
|
102
102
|
using UnityEngine;
|
103
103
|
|
104
|
-
public class
|
104
|
+
public class BallGenerator : MonoBehaviour
|
105
105
|
{
|
106
|
-
public GameObject
|
106
|
+
public GameObject ballPrefab;
|
107
|
-
private GameObject
|
107
|
+
private GameObject _ball;
|
108
|
-
private
|
108
|
+
private BallController _ballController;
|
109
109
|
|
110
110
|
// Start is called before the first frame update
|
111
111
|
void Start()
|
112
112
|
{
|
113
113
|
// ここでInstantiateを使うと、クリック前にオブジェクトが生成されてしまう。
|
114
|
-
//
|
114
|
+
// _ball = Instantiate(ballPrefab) as GameObject;
|
115
|
-
//
|
115
|
+
// _ballController = _ball.GetComponent<BallController>();
|
116
116
|
}
|
117
117
|
|
118
118
|
|
@@ -120,8 +120,8 @@
|
|
120
120
|
void Update()
|
121
121
|
{
|
122
122
|
if (Input.GetMouseButton(0)) {
|
123
|
-
|
123
|
+
_ball = Instantiate(ballPrefab) as GameObject;
|
124
|
-
|
124
|
+
_ball.GetComponent<BallController>().Shoot(new Vector3(0, 200, 2000));
|
125
125
|
}
|
126
126
|
}
|
127
127
|
}
|