Launcher.cs 582 B

12345678910111213141516171819
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Launcher : MonoBehaviour
  5. {
  6. public GameObject spawnObject;
  7. public float force;
  8. public void Spawn()
  9. {
  10. if (spawnObject)
  11. {
  12. GameObject InstanseObject = Instantiate(spawnObject, transform.position, transform.rotation) as GameObject;
  13. if (InstanseObject.GetComponent<Rigidbody>()) {
  14. InstanseObject.GetComponent<Rigidbody>().AddRelativeForce(Vector3.forward * force, ForceMode.VelocityChange);
  15. }
  16. }
  17. }
  18. }