Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created May 29, 2018 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todorok1/628aefe2c62650273957925daf43135b to your computer and use it in GitHub Desktop.
Save todorok1/628aefe2c62650273957925daf43135b to your computer and use it in GitHub Desktop.
気体分子に力を与えるスクリプト
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