void CastRay(Vector3 fwd) { //Debug.DrawRay(transform.position, fwd, Color.blue, 1f); //draws a line in the editor's scene window so you can see where the raycast is pointing if (Physics.Raycast(transform.position, fwd, out hit, rayLength) && hit.transform.gameObject.GetComponent<BNG_ZapperAction>() != null) //if you have the tag, great, if not, check for BNG_Zapper Script { onButton = true; currentGameObject = hit.transform.gameObject; if (zappedObjects.Count < 1) zappedObjects.Add(currentGameObject); za = zappedObjects[0].GetComponent<BNG_ZapperAction>(); if (za.canActivate && usingSprites) sr.color = colorOnHover; //change color of crosshairs DoHit(hit, zappedObjects[0], za); //Debug.Log("Ray is Hitting: " + currentGameObject.name); } else { //Debug.Log("No objects with BNG_ZapperAction script detected."); if (zappedObjects.Count > 0) { onButton = false; if (usingSprites) sr.color = defaultColor; za.resetBar(this, timeOnButton); timeOnButton = 0; currentGameObject = null; if (zappedObjects.Count > 0) zappedObjects.RemoveAt(0); } } }
void CastRay(Vector3 fwd) { //Debug.DrawRay(transform.position, fwd, Color.blue, 1f); //draws a line in the editor's scene window so you can see where the raycast is pointing if (Physics.Raycast(transform.position, fwd, out hit, rayLength) && hit.transform.gameObject.GetComponent <BNG_ZapperAction>() != null) //if you have the tag, great, if not, check for BNG_Zapper Script { onButton = true; currentGameObject = hit.transform.gameObject; if (zappedObjects.Count < 1) { zappedObjects.Add(currentGameObject); } za = zappedObjects[0].GetComponent <BNG_ZapperAction>(); if (za.canActivate && usingSprites) { sr.color = colorOnHover; //change color of crosshairs } DoHit(hit, zappedObjects[0], za); //Debug.Log("Ray is Hitting: " + currentGameObject.name); } else { //Debug.Log("No objects with BNG_ZapperAction script detected."); if (zappedObjects.Count > 0) { onButton = false; if (usingSprites) { sr.color = defaultColor; } za.resetBar(this, timeOnButton); timeOnButton = 0; currentGameObject = null; if (zappedObjects.Count > 0) { zappedObjects.RemoveAt(0); } } } }
void setActivationFor(GameObject go) { //print("RESET THIS GAME OBJECT: " + go); if (go == null) { Debug.LogWarning("Try checking your reference that you're passing into this function 'resetActivationFor'. Needs to find a specific game object."); return; } else { if (go.GetComponent <BNG_ZapperAction>() != null) { BNG_ZapperAction za = go.GetComponent <BNG_ZapperAction>(); if (go.GetComponent <SpriteRenderer>() != null) { SpriteRenderer sr = go.GetComponent <SpriteRenderer>(); sr.color = za.newColorOnHover; } } } }
void DoHit(RaycastHit hitInfo, GameObject hitObject, BNG_ZapperAction za) { if (za.canActivate) { print("GOOT TIMES"); timeOnButton += Time.deltaTime; za.ActivateTimer(this, timeOnButton); } else { print("FARTING"); if (usingSprites) { sr.color = defaultColor; } onButton = false; if (zappedObjects.Count > 0) { zappedObjects.RemoveAt(0); } } }
void DoHit(RaycastHit hitInfo, GameObject hitObject, BNG_ZapperAction za) { if (za.canActivate) { //print("GOOT TIMES"); timeOnButton += Time.deltaTime; za.ActivateTimer(this, timeOnButton); } else { //print("FARTING"); if(usingSprites) sr.color = defaultColor; onButton = false; if (zappedObjects.Count > 0) zappedObjects.RemoveAt(0); } }
// Use this for initialization void Start() { spriteRenderer = this.GetComponentInChildren <SpriteRenderer>(); zapper = this.GetComponentInChildren <BNG_ZapperAction>(); }