Skip to content

Instantly share code, notes, and snippets.

RaycastHit hit;
void Update()
{
Ray ray = new Ray(transform.position, transform.TransformDirection(Vector3.up));
// レイ飛ばす
if (Physics.SphereCast(ray, 1f, out hit, 100f))
{
Debug.Log(hit.collider.gameObject.name);
RaycastHit hit;
void Update()
{
// レイ飛ばす
if (Physics.BoxCast(transform.position, Vector3.one * 0.5f, transform.TransformDirection(Vector3.up), out hit))
{
Debug.Log(hit.collider.gameObject.name);
}
}
void Update()
{
// クリックした位置へのレイ取得
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
// クリックしたら
if (Input.GetMouseButtonDown(0))
{
// レイ飛ばす
using UnityEngine;
public class VectorScript : MonoBehaviour
{
void Start()
{
Vector3 vec = new Vector3(1, -5, 0);
//(1, 5, 0)になる
Vector3 res = Vector3.Reflect(vec, Vector3.up);
using UnityEngine;
public class VectorScript : MonoBehaviour
{
void Update()
{
Vector3 from = Vector3.right * -5f; //現在地
Vector3 to = transform.position; //目的地
float smoothTime = Time.deltaTime * 0.1f; //移動スピード
using UnityEngine;
public class VectorScript : MonoBehaviour
{
void Update()
{
Vector3 current = Vector3.right * -5; //現在地
Vector3 target = Vector3.right * 5; //目標値
float maxRadiansDelta = Time.time; //2点間におけるラジアンの差分の範囲内で設定する
using UnityEngine;
public class VectorScript : MonoBehaviour
{
void Update()
{
Vector3 current = Vector3.zero; //現在地
Vector3 target = Vector3.one*10; //目標値
float maxDist = Time.time; //進む距離
using UnityEngine;
public class VectorScript : MonoBehaviour
{
void Update()
{
Vector3 from = Vector3.zero;
Vector3 to = Vector3.one*10;
transform.position = Vector3.Slerp(from, to, Time.time * 0.3f);
@nopitech
nopitech / Vector3.cs
Created July 9, 2018 11:55
2点間の移動
using UnityEngine;
public class VectorScript : MonoBehaviour
{
void Update()
{
Vector3 from = Vector3.zero;
Vector3 to = Vector3.one*10;
transform.position = Vector3.Lerp(from, to, Time.time * 0.3f);
@nopitech
nopitech / Vector3.cs
Created July 9, 2018 11:47
大きさが1のベクトルを返す
using UnityEngine;
public class VectorScript : MonoBehaviour
{
void Start()
{
Vector3 vec = new Vector3(100f, 10f, 30f);
//1.0, 0.1, 0.3 になる。
Vector3 nmz = vec.normalized;