CollisionEnter.cs 801 B

1234567891011121314151617181920212223242526272829
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class CollisionEnter : MonoBehaviour
  5. {
  6. private Rigidbody rigidbody;
  7. // Start is called before the first frame update
  8. void Start()
  9. {
  10. rigidbody = GetComponent<Rigidbody>();
  11. if (rigidbody == null)
  12. {
  13. rigidbody = gameObject.AddComponent<Rigidbody>();
  14. }
  15. }
  16. private void OnCollisionEnter(Collision collision)
  17. {
  18. //print(name +" " + collision.gameObject.name);
  19. rigidbody.useGravity = true;
  20. rigidbody.mass = 0.1f;
  21. }
  22. // Update is called once per frame
  23. void Update()
  24. {
  25. // transform.position = new Vector3(transform.position.x, transform.position.y - 0.01f * Time.deltaTime, transform.position.z);
  26. }
  27. }