0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ARFoundation ボールを平面に衝突させる・反射させる

Last updated at Posted at 2021-07-26

Sphereを作成し、名前をBallに変更する。サイズを調整する
880EF088-9A3C-4285-AA85-03E2FB32DCA4_4_5005_c.jpeg

BallにRigidbodyをつける
12149691-A9A3-4EA6-9AC6-7862C29F53D8.jpeg

BallThrower
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BallThrower : MonoBehaviour
{
    [SerializeField]
    private GameObject ballPrefab;
    //ボールの速さ
    float shotSpeed = 10.0f;
    void Update()
    {
        //画面がタッチされたら処理を行う
        if (Input.touchCount > 0)
        {
            //画面タッチの情報を取得する
            Touch touch = Input.GetTouch(0);
            //画面タッチの開始時のみ処理を行う
            if (touch.phase == TouchPhase.Began)
            {
                //ボールを生成する
                GameObject ball = Instantiate(ballPrefab, Camera.main.transform);
                //ボールにカメラ前方への速度を与える
                ball.GetComponent<Rigidbody>().velocity
                = Camera.main.transform.forward * shotSpeed;
            }
        }
    }
}

Ballをプレハブ化する。Gameobjectを作成し、名前をBallThrowerに変更し、BallTHrowerスクリプトをつける。Ballプレハブをアタッチする。
D0B2BD02-CDD8-43AD-8E22-BD0BD9CE0E42_4_5005_c.jpeg

※タッチ操作が被っていたのでRayCastスクリプトのチェックを外した
E6F9696F-76C3-45C1-BF09-0D76A1AA171E.jpeg

ビルドする

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?