3
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 5 years have passed since last update.

unityでrayをcollider裏面に当てる方法

Last updated at Posted at 2019-05-09

Physics.queriesHitBackfaces = true;
↑このAPIを使えばいい!
5.5からのAPIです。

テスト結果:
image.png

Shooter.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Shooter : MonoBehaviour
{
    public GameObject testBox;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        Physics.queriesHitBackfaces = true;
        RaycastHit hit;
        if(Physics.Raycast(transform.position,transform.forward,out hit,1000)){
            Instantiate(testBox,hit.transform.position,Quaternion.identity);
        }
    }
}

3
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
3
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?