private void SelectObject() { if (Input.GetButtonDown("Fire1")) { var ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo)) { var selected = InterfaceUtility.GetInterface <ISelectable>(hitInfo.collider.gameObject); _selectedGameObject = selected != null ? hitInfo.collider.gameObject : null; if (selected != null) { selected.Selected(); } } else { _selectedGameObject = null; } } }
private void OnTriggerEnter(Collider other) { // TODO - Boost player when player enters the trigger collider // Check if it is the player, then // 1. Boost it by passing the boostAmount. // - to confirm if the boost occurs, check console log. // It will print a statement saying it is boosting player by an amount. // 2. Play the audio when it confirms that the player passed through and boosts them. // // Just a thought - how would you change your code to make this also boost an enemy? List <IMoveable> boostList; InterfaceUtility.GetInterfaces <IMoveable>(out boostList, other.gameObject); foreach (IMoveable boostable in boostList) { foreach (AudioClip sound in sounds) { audioSource.PlayOneShot(sound); } boostable.Boost(boostAmount, ForceMode.Acceleration); } /* answer to the problem * if(other.TryGetComponent(out IBoostable boostableObj)) * { * boostableObj.Boost(boostAmount, ForceMode.Acceleration); * audioSource.Play(); * } */ }
public string Login() { if (!AppSSOBLL.TOEACAuthenticat("01", AppSSOBLL.GetTimeStamp(), InterfaceUtility.GetNodeValueForConfig("BackUrl"), "")) { return(JSONHelper.FromString(true, "连接成功")); } return(JSONHelper.FromString(true, "连接失败")); }
void OnCollisionEnter(Collision collision) { var script = InterfaceUtility.GetMonoBehaviourImplementTheInterface <ICanBeInteracted>(collision.gameObject); if (script != null) { var canBeInteracted = script as ICanBeInteracted; if (canBeInteracted.IsAutoInteracted) { canBeInteracted.Interact(HeroStuff); } } }
private void AutoUpdateActiveObjToInteract() { var all = FindObjectsOfType <GameObject>(); var canBeInteracted = InterfaceUtility.FindObjectsImplementOfInterface <ICanBeInteracted>(all); var closest = canBeInteracted .Where(x => Vector3.Distance(transform.position, x.transform.position) < DistnaceOfInteract) .OrderBy(x => Vector3.Distance(transform.position, x.transform.position)).FirstOrDefault(); if (ActiveObjToInteract != closest) { GetICanBeInteracted()?.DeselectAsActive(); ActiveObjToInteract = closest; GetICanBeInteracted()?.SelectAsActive(); } }
private ICanBeInteracted GetICanBeInteracted() { return(InterfaceUtility.GetMonoBehaviourImplementTheInterface <ICanBeInteracted>(ActiveObjToInteract) as ICanBeInteracted); }