Bullet.cs 759 B

12345678910111213141516171819202122232425262728293031
  1. using Photon.Realtime;
  2. using UnityEngine;
  3. namespace Photon.Pun.Demo.Asteroids
  4. {
  5. public class Bullet : MonoBehaviour
  6. {
  7. public Player Owner { get; private set; }
  8. public void Start()
  9. {
  10. Destroy(gameObject, 3.0f);
  11. }
  12. public void OnCollisionEnter(Collision collision)
  13. {
  14. Destroy(gameObject);
  15. }
  16. public void InitializeBullet(Player owner, Vector3 originalDirection, float lag)
  17. {
  18. Owner = owner;
  19. transform.forward = originalDirection;
  20. Rigidbody rigidbody = GetComponent<Rigidbody>();
  21. rigidbody.velocity = originalDirection * 200.0f;
  22. rigidbody.position += rigidbody.velocity * lag;
  23. }
  24. }
  25. }