Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class sugarDetection : MonoBehaviour
- {
- public List<ParticleCollisionEvent> collisionEvents;
- public ParticleSystem sugar;
- public mug mugscript;
- public GameObject sugarSimulator;
- public GameObject[] cloner;
- public int numCollisionEvents = 0;
- // Start is called before the first frame update
- void Start()
- {
- mugscript = GameObject.Find("Medium").GetComponent<mug>();
- //sugar = FindObjectOfType<ParticleSystem>();
- }
- void OnParticleCollision(GameObject other)
- {
- Debug.Log("Hit");
- numCollisionEvents = sugar.GetCollisionEvents(other, collisionEvents);
- Rigidbody rb = other.GetComponent<Rigidbody>();
- int i = 0;
- if (other.tag == "Interactable")
- {
- Debug.Log("hit");
- }
- while (i < numCollisionEvents)
- {
- if (rb)
- {
- Vector3 pos = collisionEvents[i].intersection;
- Vector3 force = collisionEvents[i].velocity * 10;
- rb.AddForce(force);
- }
- i++;
- }
- }
- // Update is called once per frame
- void Update()
- {
- RaycastHit hit;
- Vector3 forward = transform.TransformDirection(0, 0.47f, 1) * 100;
- Debug.DrawRay(transform.position + transform.up * 3.2f, forward, Color.green);
- if (Physics.Raycast(transform.position + transform.up * 3.2f, forward, out hit, 100f))
- {
- if (hit.collider.tag == "Interactable")
- {
- Debug.Log("hit, sugaaaaa");
- mugscript.hassugar = true;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement