using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestVelocity : MonoBehaviour {
public Rigidbody rb;
// Use this for initialization
void Start () {
rb = this.gameObject.AddComponent<Rigidbody> ();
rb.useGravity = true;
rb.mass = 1.0f;
rb.drag = 0.0f;
}
// Update is called once per frame
void Update () {
//if(Input.GetButtonDown("Jump"))
//rb.velocity=new Vector3(0.0f,10.0f,0.0f);
}
void FixedUpdate(){
if (Input.GetButtonDown ("Jump"))
rb.velocity = new Vector3 (0.0f, 10.0f, 0.0f);
}
void OnGUI(){
GUILayout.Label ("Please press SPASE key...");
}
}
TestAddForce
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestAddForce : MonoBehaviour {
public Rigidbody rb;
public float thrust = 1.0f;
// Use this for initialization
void Start () {
rb = gameObject.AddComponent<Rigidbody> () as Rigidbody;//rb=gameObject.AddComponent<Rigidbody>();
rb.useGravity=true;
rb.mass = 10.0f;
rb.drag = 0.0f;
}
// Update is called once per frame
void Update () {
}
void FixedUpdate(){
//The following codes are used for testing Rigidbody.AddForce
rb.AddForce(Vector3.forward* thrust,ForceMode.Force);
//rb.AddForce(transform.forward* thrust,ForceMode.Force);//This will lead to different effect
//Debug.log(transform.forward);
//Try different ForceMode
//rb.AddForce(Vector3.forward* thrust,ForceMode.Impulse);
//rb.AddForce(transform.forward* thrust,ForceMode.Impulse);
//rb.AddForce(Vector3.forward* thrust,ForceMode.Acceleration);
//rb.AddForce(transform.forward* thrust,ForceMode.Acceleration);
//rb.AddForce(Vector3.forward* thrust,ForceMode.VelocityChange);
//rb.AddForce(transform.forward* thrust,ForceMode.Acceleration);
//The following codes are used for testing Rigidbody.AddRelativeForce
//rb.AddRelativeForce(Vector3.forward* thrust,ForceMode.Force);
//rb.AddRelativeForce(transform.forward* thrust,ForceMode.Force);
//rb.AddRelativeForce(Vector3.forward* thrust,ForceMode.Impulse);
}
}
Ball.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ball : MonoBehaviour {
// Use this for initialization
void Start () {
this.GetComponent<Rigidbody> ().velocity = new Vector3 (-0.7f, 6.0f, 0.0f);
}
// Update is called once per frame
void Update () {
}
}
Launcher.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Launcher : MonoBehaviour {
public GameObject ballPrefab;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown (1)) {
Instantiate (this.ballPrefab);
}
}
}
Player.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Launcher : MonoBehaviour {
public GameObject ballPrefab;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown (1)) {
Instantiate (this.ballPrefab);
}
}
}