Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created May 14, 2018 07:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save todorok1/f46071ad53fbed13a4980ccb6821db82 to your computer and use it in GitHub Desktop.
UnityのRigidbodyでdragをいじって水中を表現
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WaterChecker : MonoBehaviour {
Rigidbody rb;
string waterTag = "Water";
public float waterDrag = 3.0f;
float defaultDrag = 0.0f;
void Start(){
rb = gameObject.GetComponent<Rigidbody>();
defaultDrag = rb.drag;
}
void OnTriggerEnter(Collider other){
if (other.gameObject.tag == waterTag){
// 水の中の抵抗をセット
rb.drag = waterDrag;
}
}
void OnTriggerExit(Collider other){
if (other.gameObject.tag == waterTag){
// 通常の抵抗をセット
rb.drag = defaultDrag;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment