Created
May 14, 2018 07:48
-
-
Save todorok1/f46071ad53fbed13a4980ccb6821db82 to your computer and use it in GitHub Desktop.
UnityのRigidbodyでdragをいじって水中を表現
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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