Created
May 29, 2018 12:17
-
-
Save todorok1/628aefe2c62650273957925daf43135b to your computer and use it in GitHub Desktop.
気体分子に力を与えるスクリプト
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 GasMolecularMover : MonoBehaviour { | |
public float minSpeed = 20f; | |
public float maxSpeed = 30f; | |
Vector3 force = Vector3.zero; | |
Rigidbody rb; | |
bool isShoot; | |
void Start(){ | |
force.x = GetRandomSpeed(); | |
force.y = GetRandomSpeed(); | |
force.z = GetRandomSpeed(); | |
rb = gameObject.GetComponent<Rigidbody>(); | |
} | |
void FixedUpdate(){ | |
if (!isShoot){ | |
rb.AddForce(force, ForceMode.VelocityChange); | |
isShoot = true; | |
} | |
} | |
float GetRandomSpeed(){ | |
float speed = 0f; | |
speed = Random.Range(minSpeed, maxSpeed); | |
return speed; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment