Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
気体分子に力を与えるスクリプト
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
You can’t perform that action at this time.