IEnumerator CheckLookObject() { while (_currentObject != null) { RaycastHit hit; Ray ray = new Ray(transform.position, transform.forward); //Assign object as current object if (Physics.Raycast(ray, out hit, 1000)) { if (hit.collider.gameObject.tag == "Cocktail") { Debug.Log("glass of" + hit.collider.gameObject.GetComponent <InteractableObjects>().GetDrinkType()); _lookingAtGlassCup = true; _currentLookingGlassCup = hit.collider.gameObject.GetComponent <InteractableObjects>(); if (IsHoldingObject()) { _src2 = _currentLookingGlassCup.GetDrinkType(); } } else { _lookingAtGlassCup = false; } } else { // debugText.text = "Not looking at glass cup"; _lookingAtGlassCup = false; } //Check at preferred frame interval yield return(new WaitForSeconds(frameInterval * Time.deltaTime)); } }
public void GrabObject() { // If you don't have anything if (_currentObject == null) { RaycastHit hit; Ray ray = new Ray(transform.position, transform.forward); int touchableDistance = 1000; //Assign object as current object if (Physics.Raycast(ray, out hit, touchableDistance)) { //Check if object is interactable if (hit.collider.gameObject.GetComponent <InteractableObjects>() != null && hit.collider.gameObject.tag != "Cocktail") { _currentObject = hit.collider.gameObject; _currentObject.transform.rotation = Quaternion.identity; _currentRB = _currentObject.GetComponent <Rigidbody>(); _currentRB.detectCollisions = false; _currentRB.useGravity = false; _interactableObject = _currentObject.GetComponent <InteractableObjects>(); MoveObjectTowardsPlayer(); StartCoroutine("CheckLookObject"); /////////////////////////////////////////////// if (_temp = _currentObject.GetComponent <InteractableObjects>()) { if (_src1 != DRINK_TYPE.EMPTY) { _src1 = _temp.GetDrinkType(); _alcoholContent1 = _temp.GetAlcoholContent(); } } ///////////////////////////////////////////////// } } } else { } }
public void PourCurrentDrink() { // Animetion rotateArmToDrink(ARM_MOTION.DRINKING, true); InteractableObjects currentObject = _currentObject.gameObject.GetComponent <InteractableObjects>(); //Only can pour drinks if (currentObject.GetObjectType() == OBJECT_TYPE.DRINKS) { // Current I have thing. DRINK_TYPE src1 = currentObject.GetDrinkType(); // Current I look thing. DRINK_TYPE src2 = _currentLookingGlassCup.GetDrinkType(); switch (_currentLookingGlassCup.GetGlassState()) { case GLASS_STATE.EMPTY: //Sound AudioSource.PlayClipAtPoint(pourSound, transform.position); // If I look cup is empty, I just pour. _currentLookingGlassCup.SetDrinkType(src1); _currentLookingGlassCup.AddAlcoholContent(src1); _currentLookingGlassCup.SetGlassState(GLASS_STATE.HALF); Debug.Log("Glass is " + currentObject.GetDrinkType()); Debug.Log("Glass is " + currentObject.GetGlassState()); Debug.Log("This AC is " + currentObject.GetAlcoholContent()); Debug.Log("POURING"); break; case GLASS_STATE.HALF: //Sound AudioSource.PlayClipAtPoint(pourSound, transform.position); // I pour the same thing if (src1 == src2) { _currentLookingGlassCup.SetDrinkType(src1); _currentLookingGlassCup.AddAlcoholContent(src1); } // I pour the waste. or I pour any thing to the waste. if (src1 == DRINK_TYPE.WASTE || src2 == DRINK_TYPE.WASTE) { _currentLookingGlassCup.SetDrinkType(DRINK_TYPE.WASTE); _currentLookingGlassCup.AddAlcoholContent(src1); } // I investigate combination when I pour any drink to other drink. foreach (ChartData data in _cd) { if (data._src1 == src1) { if (data._src2 == src2) { _currentLookingGlassCup.SetDrinkType(data._compost); _currentLookingGlassCup.AddAlcoholContent(src1); } } if (data._src1 == src2) { if (data._src2 == src1) { _currentLookingGlassCup.SetDrinkType(data._compost); _currentLookingGlassCup.AddAlcoholContent(src1); } } } _currentLookingGlassCup.SetGlassState(GLASS_STATE.FULL); Debug.Log("Glass is " + _currentLookingGlassCup.GetDrinkType()); Debug.Log("Glass is " + _currentLookingGlassCup.GetGlassState()); Debug.Log("This AC is " + currentObject.GetAlcoholContent()); Debug.Log("POURING"); break; case GLASS_STATE.FULL: // Do nothing break; default: // This combination wasn't in chart data. _currentLookingGlassCup.SetDrinkType(DRINK_TYPE.WASTE); break; } } }