Guest User

Untitled

a guest
May 24th, 2019
75
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class sugarDetection : MonoBehaviour
  6. {
  7. public List<ParticleCollisionEvent> collisionEvents;
  8. public ParticleSystem sugar;
  9. public mug mugscript;
  10. public GameObject sugarSimulator;
  11. public GameObject[] cloner;
  12. public int numCollisionEvents = 0;
  13. // Start is called before the first frame update
  14. void Start()
  15. {
  16. mugscript = GameObject.Find("Medium").GetComponent<mug>();
  17. //sugar = FindObjectOfType<ParticleSystem>();
  18. }
  19.  
  20. void OnParticleCollision(GameObject other)
  21. {
  22.  
  23. Debug.Log("Hit");
  24. numCollisionEvents = sugar.GetCollisionEvents(other, collisionEvents);
  25.  
  26. Rigidbody rb = other.GetComponent<Rigidbody>();
  27. int i = 0;
  28.  
  29. if (other.tag == "Interactable")
  30. {
  31. Debug.Log("hit");
  32. }
  33.  
  34. while (i < numCollisionEvents)
  35. {
  36. if (rb)
  37. {
  38. Vector3 pos = collisionEvents[i].intersection;
  39. Vector3 force = collisionEvents[i].velocity * 10;
  40. rb.AddForce(force);
  41. }
  42. i++;
  43. }
  44. }
  45. // Update is called once per frame
  46. void Update()
  47. {
  48. RaycastHit hit;
  49. Vector3 forward = transform.TransformDirection(0, 0.47f, 1) * 100;
  50. Debug.DrawRay(transform.position + transform.up * 3.2f, forward, Color.green);
  51. if (Physics.Raycast(transform.position + transform.up * 3.2f, forward, out hit, 100f))
  52. {
  53. if (hit.collider.tag == "Interactable")
  54. {
  55. Debug.Log("hit, sugaaaaa");
  56. mugscript.hassugar = true;
  57. }
  58. }
  59. }
  60. }
RAW Paste Data