// Update is called once per frame void Update() { playerPos = player.transform.position; Vector3 origin = playerPos; Vector3 direction = transform.TransformDirection(Vector3.back); //new code RaycastHit[] hits; hits = Physics.SphereCastAll(origin, raySphereThickness, direction, wallMask.value); foreach (RaycastHit hit in hits) { if (hit.collider.tag == ("Wall")) { MeshRenderer R = hit.collider.GetComponent <MeshRenderer>(); if (R == null) { continue; // no renderer attached? go to next hit } AutoTransparent AT = R.GetComponent <AutoTransparent>(); if (AT == null) // if no script is attached, attach one { AT = R.gameObject.AddComponent <AutoTransparent>(); } AT.BeTransparent(m_TransMat); // get called every frame to reset the falloff} } } }
//public float DistanceToPlayer = 5.0f; void Update() { if (TurnManager.GetCurrentPlayer() != null) { Transform target = TurnManager.GetCurrentPlayer().transform; actualHits.AddRange(RaycastTo(target)); if (tilesToClear != null) { foreach (TileBFSScript tile in tilesToClear) { actualHits.AddRange(RaycastTo(tile.transform)); } } foreach (RaycastHit hit in actualHits) { Renderer R = hit.collider.GetComponent <Renderer>(); if (R == null) { continue; } AutoTransparent AT = R.GetComponent <AutoTransparent>(); if (AT == null) // if no script is attached, attach one { AT = R.gameObject.AddComponent <AutoTransparent>(); } AT.BeTransparent(); } actualHits.Clear(); } }
private void Update() { RaycastHit[] hits; //Store array of objects hit by raycast //If object is hit by ray within given player distance hits = Physics.RaycastAll(transform.position, transform.forward, DistanceToPlayer); foreach (RaycastHit hit in hits) { //Get render Renderer R = hit.collider.GetComponent <Renderer>(); if (R == null) { continue; } // no renderer attached? go to next hit AutoTransparent AT = R.GetComponent <AutoTransparent>(); if (AT == null) // if no script is attached to object, attach one { AT = R.gameObject.AddComponent <AutoTransparent>(); AT.TransparentMaterial = TransparentMaterial; AT.FadeInTimeout = FadeInTimeout; AT.FadeOutTimeout = FadeOutTimeout; AT.TargetTransparency = TargetTransparency; } AT.BeTransparent(); // get called every frame to reset the falloff after object leaves range } }
void Update() { // you can also use CapsuleCastAll() // TODO: setup your layermask it improve performance and filter your hits. playerOffset = new Vector3(-0.1247f, 0.1f, -0.1247f); //The location to point to origin = this.transform.position; dir = rayCastObj.transform.position - origin; Debug.DrawRay(this.transform.position + playerOffset, dir, Color.blue, 0.01f, false); RaycastHit[] hits; hits = Physics.RaycastAll(this.transform.position + playerOffset, dir, DistanceToPlayer); foreach (RaycastHit hit in hits) { Renderer R = hit.collider.GetComponent <Renderer>(); if (R == null) { continue; // no renderer attached? go to next hit } // TODO: maybe implement here a check for GOs that should not be affected like the player AutoTransparent AT = R.GetComponent <AutoTransparent>(); if (AT == null) // if no script is attached, attach one { AT = R.gameObject.AddComponent <AutoTransparent>(); } AT.BeTransparent(); // get called every frame to reset the falloff } }
void Update() { RaycastHit[] hits; // you can also use CapsuleCastAll() // TODO: setup your layermask it improve performance and filter your hits. Vector3 direction = Vector3.Normalize(player.transform.position - transform.position); //hits = Physics.RaycastAll(transform.position, direction, distanceToPlayer); hits = Physics.CapsuleCastAll(transform.position, transform.position, transparencyRadius, direction, distanceToPlayer - transparencyRadius, layerToFade); foreach (RaycastHit hit in hits) { Renderer R = hit.collider.GetComponent <Renderer>(); if (R == null) { continue; } // no renderer attached? go to next hit // TODO: maybe implement here a check for GOs that should not be affected like the player AutoTransparent AT = R.GetComponent <AutoTransparent>(); if (AT == null) // if no script is attached, attach one { AT = R.gameObject.AddComponent <AutoTransparent>(); AT.TransparentMaterial = transparentMaterial; AT.FadeInTimeout = fadeInTimeout; AT.FadeOutTimeout = fadeOutTimeout; AT.TargetTransparency = targetTransparency; } AT.BeTransparent(); // get called every frame to reset the falloff } }
void TransparentWalls() { RaycastHit[] hits; // you can also use CapsuleCastAll() // TODO: setup your layermask it improve performance and filter your hits. hits = Physics.RaycastAll(transform.position, (this.transform.rotation * Vector3.forward) + (target.transform.position - this.transform.position)); foreach (RaycastHit hit in hits) { if (hit.transform.tag != Tags.Wall) { continue; } var renderers = hit.collider.GetComponentsInChildren <Renderer>(); if (renderers == null || renderers.Length == 0) { continue; // no renderer attached? go to next hit } // TODO: maybe implement here a check for GOs that should not be affected like the player var room = hit.transform.GetComponentInParent <Room>(); if (room != null && room.IsLit == true) { foreach (var R in renderers) { AutoTransparent AT = R.GetComponent <AutoTransparent>(); if (AT == null) // if no script is attached, attach one { AT = R.gameObject.AddComponent <AutoTransparent>(); } AT.BeTransparent(); // get called every frame to reset the falloff } } } }
// Update is called once per frame void Update() { //transform.position = new Vector3(Player.transform.position.x + xOffset, Player.transform.position.y + yOffset, Player.transform.position.z + zOffset); //RaycastHit[] hits; // you can also use CapsuleCastAll() // TODO: setup your layermask it improve performance and filter your hits. if (Physics.Raycast(transform.position, transform.forward, out hit, 4f)) { //Debug.Log ("Camera's Raycast hit " + hit.collider); if (hit.collider != Player.gameObject.collider) { //Debug.Log ("Camera's Raycast hit something that's not a player!"); Renderer R = hit.collider.renderer; // if (R == null) // continue; // no renderer attached? go to next hit // TODO: maybe implement here a check for GOs that should not be affected like the player if (R != null) { AutoTransparent AT = R.GetComponent <AutoTransparent>(); if (AT == null) // if no script is attached, attach one { AT = R.gameObject.AddComponent <AutoTransparent>(); } AT.BeTransparent(); // get called every frame to reset the falloff } } } }
private void Update() { RaycastHit[] hits; // you can also use CapsuleCastAll() // TODO: setup your layermask it improve performance and filter your hits. float hover = 0f; switch (gameManager.playerLocation) { case locationType.Space: DistanceToPlayer = spaceHeight; hover = gameManager.hoverHeight; break; case locationType.Air: DistanceToPlayer = airHeight; hover = gameManager.airHoverHeight; break; case locationType.Building: DistanceToPlayer = buildingHeight; hover = gameManager.airHoverHeight; break; default: hover = 3.5f; DistanceToPlayer = groundHeight; //gameManager.mainOffset; break; } hits = Physics.RaycastAll(transform.position, transform.forward, DistanceToPlayer - hover); foreach (RaycastHit hit in hits) { Renderer R = hit.collider.GetComponent <Renderer>(); //Debug.Log(hit.collider.gameObject.name); if (R == null) { continue; } // no renderer attached? go to next hit // TODO: maybe implement here a check for GOs that should not be affected like the player AutoTransparent AT = R.GetComponent <AutoTransparent>(); if (AT == null) // if no script is attached, attach one { AT = R.gameObject.AddComponent <AutoTransparent>(); AT.TransparentMaterial = TransparentMaterial; AT.FadeInTimeout = FadeInTimeout; AT.FadeOutTimeout = FadeOutTimeout; AT.TargetTransparency = TargetTransparency; } AT.BeTransparent(); // get called every frame to reset the falloff } }
void Update() { RaycastHit[] hits; hits = Physics.RaycastAll(transform.position, transform.forward, Vector3.Distance(this.transform.position, target.position)); foreach (RaycastHit hit in hits) { Debug.DrawLine(this.transform.position, hit.collider.gameObject.transform.position, Color.magenta); if (hit.collider.gameObject.tag == "LookTrought") { Renderer R = hit.collider.GetComponent <Renderer>(); AutoTransparent AT = R.GetComponent("AutoTransparent") as AutoTransparent; AT.BeTransparent(); } } }
void Update() { RaycastHit[] hits; // Raycast, but filter the layers based on the mask hits = Physics.RaycastAll(transform.position, transform.forward, comboCamera.getDistanceToPlayer(), mask); foreach (RaycastHit hit in hits) { Renderer R = hit.collider.renderer; if (R == null) { continue; // no renderer attached? go to next hit } AutoTransparent AT = R.GetComponent <AutoTransparent>(); if (AT == null) // if no script is attached, attach one { AT = R.gameObject.AddComponent <AutoTransparent>(); } AT.BeTransparent(); // get called every frame to reset the falloff } }
void Update() { RaycastHit[] hits; Collider[] colliders = Physics.OverlapSphere(transform.position, DistanceToPlayer); foreach (Collider collider in colliders) { Renderer R = collider.GetComponent <Renderer>(); if (R == null) { continue; // no renderer attached? go to next hit } AutoTransparent AT = R.GetComponent <AutoTransparent>(); if (AT != null) // if no script is attached, attach one { AT.BeTransparent(); // get called every frame to reset the falloff } } }
void Update() { RaycastHit[] hits; hits = Physics.RaycastAll(transform.position, transform.forward, distanceToClear); foreach (RaycastHit hit in hits) { Renderer R = hit.collider.renderer; if (R == null) { continue; // no renderer attached? go to next hit } AutoTransparent AT = R.GetComponent <AutoTransparent>(); if (AT == null) // if no script is attached, attach one { AT = R.gameObject.AddComponent <AutoTransparent>(); } AT.BeTransparent(); // get called every frame to reset the falloff } }
// Update is called once per frame void Update() { RaycastHit[] hits; Debug.DrawRay(transform.position, transform.forward, Color.green, 20); hits = Physics.RaycastAll(transform.position, transform.forward, getDirectionFromCameraToPlayer()._distance); Debug.Log(hits.Length.ToString()); foreach (RaycastHit hit in hits) { Renderer R = hit.collider.GetComponent <Renderer>(); if (R == null) { continue; } AutoTransparent AT = R.GetComponent <AutoTransparent>(); if (AT == null) { continue; } AT.BeTransparent(); } }
// Update is called once per frame void Update() { RaycastHit[] hits; hits = Physics.RaycastAll(transform.position, transform.forward, DistanceToPlayer); foreach (RaycastHit hit in hits) { Renderer R = hit.collider.GetComponent <Renderer>(); if (R == null) { continue; } if (R.gameObject.tag == "pickable") { continue; } if (hit.collider.gameObject.tag != "Player" && hit.collider.gameObject.tag != "Field") { AutoTransparent AT = R.GetComponent <AutoTransparent>(); if (AT == null) { AT = R.gameObject.AddComponent <AutoTransparent>(); } if (R.gameObject.tag == "Tree") { AT.m_oldMaterial = standardTree; AT.m_newMaterial = transparentTree; } else if (R.gameObject.tag == "Bush") { AT.m_oldMaterial = standardBush; AT.m_newMaterial = transparentBush; } AT.BeTransparent(); } } }
void CheckIfViewBlocked() { Vector3 screenCenter = new Vector3(0.5f, 0.5f, 0f); Ray _ray = Camera.main.ViewportPointToRay(screenCenter); RaycastHit _rayHit = new RaycastHit(); LayerMask layerMask = 1 << LayerMask.NameToLayer("PlayerSearchLayer") | 1 << LayerMask.NameToLayer("ZombieSearchLayer") | 1 << LayerMask.NameToLayer("TriggerLayer"); if (Physics.Raycast(_ray, out _rayHit, _distanceToPlayer, ~layerMask) && _rayHit.transform != Player.Instance.transform) { Renderer R = _rayHit.collider.renderer; // TODO: maybe implement here a check for GOs that should not be affected like the player AutoTransparent AT = R.GetComponent <AutoTransparent>(); if (AT == null) // if no script is attached, attach one { AT = R.gameObject.AddComponent <AutoTransparent>(); } AT.BeTransparent(); // get called every frame to reset the falloff } }
void Update() { RaycastHit[] hits; // you can also use CapsuleCastAll() // TODO: setup your layermask it improve performance and filter your hits. hits = Physics.RaycastAll(transform.position, transform.forward, DistanceToPlayer); foreach (RaycastHit hit in hits) { Renderer R = hit.collider.GetComponent <Renderer>(); if (R == null) { continue; // no renderer attached? go to next hit } // TODO: maybe implement here a check for GOs that should not be affected like the player AutoTransparent AT = R.GetComponent <AutoTransparent>(); if (AT == null) // if no script is attached, attach one { AT = R.gameObject.AddComponent <AutoTransparent>(); } AT.BeTransparent(); // get called every frame to reset the falloff } }
private void Update() { RaycastHit[] hits; // you can also use CapsuleCastAll() // TODO: setup your layermask it improve performance and filter your hits. Vector3 direction = (m_Player.GetComponent <Transform>().position + new Vector3(0, 1f, 0)) - transform.position; hits = Physics.RaycastAll(transform.position, direction.normalized, direction.magnitude); Debug.DrawLine(transform.position, m_Player.GetComponent <Transform>().position); foreach (RaycastHit hit in hits) { if (hit.collider.CompareTag("Obstacle")) { Renderer[] R = hit.collider.GetComponentsInChildren <Renderer>(); if (R == null) { continue; } // no renderer attached? go to next hit // TODO: maybe implement here a check for GOs that should not be affected like the player foreach (Renderer r in R) { //Debug.Log(r.gameObject.name); // r.material = TransparentMaterial; AutoTransparent AT = r.GetComponent <AutoTransparent>(); if (AT == null) // if no script is attached, attach one { AT = r.gameObject.AddComponent <AutoTransparent>(); } AT.BeTransparent(); // get called every frame to reset the falloff } } } }
void setAutoTransparentOnObject(GameObject alphaObject) { if (alphaObject.GetComponent <InvisibleToVisible>()) { return; } if (alphaObject.GetComponent <InvisibleToVisible2>()) { return; } if (alphaObject.GetComponent <VisibleToInvisible>()) { return; } AutoTransparent AT = alphaObject.GetComponent <AutoTransparent>(); if (AT == null) // if no script is attached, attach one { AT = alphaObject.gameObject.AddComponent <AutoTransparent>(); } AT.BeTransparent(); // get called every frame to reset the falloff }
void Update() { if (player.GetComponent <PlayerBehavior> ().panMode == true) { if (Input.touches.Length > 0 && canTouch) { Touch t = Input.GetTouch(0); if (initialTouch) { GameObject.Find("GamePanel").SendMessage("Change"); if (PlayerPrefs.GetInt("Vibrate") == 1) { Handheld.Vibrate(); } touchStart = t.position; initialTouch = false; } Vector2 touchCurrent = t.position; Vector2 touchDistance = new Vector2(touchCurrent.x - touchStart.x, touchCurrent.y - touchStart.y); transform.position += transform.right * touchDistance.x / 1250.0f; transform.position += transform.up * touchDistance.y / 1250.0f; if (t.phase == TouchPhase.Ended) { GameObject.Find("GamePanel").SendMessage("Change"); canTouch = false; } } else { cameraStartPos = parent.transform.position + new Vector3(51.0f, 35.0f, 53.0f); cameraTimer += Time.deltaTime / 15.0f; transform.position = Vector3.Lerp(transform.position, cameraStartPos, cameraTimer); if (cameraTimer >= 0.1f) { player.GetComponent <PlayerBehavior> ().panMode = false; initialTouch = true; canTouch = true; cameraTimer = 0.0f; } } } else { if (changeView) { if (currentView == 5) { if (timer < 1.0f) { myCamera.fieldOfView = Mathf.Lerp(fov5, fov1, timer); timer += Time.deltaTime; if (timer >= 1.0f) { PlayerPrefs.SetInt("Zoom", 1); currentView = 1; changeView = false; } } } if (currentView == 1) { if (timer < 1.0f) { myCamera.fieldOfView = Mathf.Lerp(fov1, fov2, timer); timer += Time.deltaTime * 2.0f; if (timer >= 1.0f) { PlayerPrefs.SetInt("Zoom", 2); currentView = 2; changeView = false; } } } if (currentView == 2) { if (timer < 1.0f) { myCamera.fieldOfView = Mathf.Lerp(fov2, fov3, timer); timer += Time.deltaTime * 2.0f; if (timer >= 1.0f) { PlayerPrefs.SetInt("Zoom", 3); currentView = 3; changeView = false; } } } if (currentView == 3) { if (timer < 1.0f) { myCamera.fieldOfView = Mathf.Lerp(fov3, fov4, timer); timer += Time.deltaTime * 2.0f; if (timer >= 1.0f) { PlayerPrefs.SetInt("Zoom", 4); currentView = 4; changeView = false; } } } if (currentView == 4) { if (timer < 1.0f) { myCamera.fieldOfView = Mathf.Lerp(fov4, fov5, timer); timer += Time.deltaTime * 2.0f; if (timer >= 1.0f) { PlayerPrefs.SetInt("Zoom", 5); currentView = 5; changeView = false; } } } } if (liteMode == 0) { RaycastHit[] hits; hits = Physics.RaycastAll(transform.position, transform.forward, DistanceToPlayer); foreach (RaycastHit hit in hits) { //Debug.Log("Found object to fade!"); Renderer R = hit.collider.GetComponent <Renderer> (); if (R == null) { continue; // no renderer attached? go to next hit } AutoTransparent AT = R.GetComponent <AutoTransparent> (); if (AT == null) // if no script is attached, attach one { AT = R.gameObject.AddComponent <AutoTransparent> (); //Debug.Log("Adding script!"); } AT.BeTransparent(); // get called every frame to reset the falloff } hits = Physics.RaycastAll(transform.position + new Vector3(0.0f, -0.5f, 0.0f), transform.forward, DistanceToPlayer); foreach (RaycastHit hit in hits) { //Debug.Log("Found object to fade!"); Renderer R = hit.collider.GetComponent <Renderer>(); if (R == null) { continue; // no renderer attached? go to next hit } AutoTransparent AT = R.GetComponent <AutoTransparent>(); if (AT == null) { // if no script is attached, attach one AT = R.gameObject.AddComponent <AutoTransparent>(); //Debug.Log("Adding script!"); } AT.BeTransparent(); // get called every frame to reset the falloff } hits = Physics.RaycastAll(transform.position + new Vector3(0.0f, 0.5f, 0.0f), transform.forward, DistanceToPlayer); foreach (RaycastHit hit in hits) { //Debug.Log("Found object to fade!"); Renderer R = hit.collider.GetComponent <Renderer> (); if (R == null) { continue; // no renderer attached? go to next hit } AutoTransparent AT = R.GetComponent <AutoTransparent> (); if (AT == null) // if no script is attached, attach one { AT = R.gameObject.AddComponent <AutoTransparent> (); //Debug.Log("Adding script!"); } AT.BeTransparent(); // get called every frame to reset the falloff } hits = Physics.RaycastAll(transform.position + new Vector3(0.0f, 1.0f, 0.0f), transform.forward, DistanceToPlayer); foreach (RaycastHit hit in hits) { //Debug.Log("Found object to fade!"); Renderer R = hit.collider.GetComponent <Renderer> (); if (R == null) { continue; // no renderer attached? go to next hit } AutoTransparent AT = R.GetComponent <AutoTransparent> (); if (AT == null) // if no script is attached, attach one { AT = R.gameObject.AddComponent <AutoTransparent> (); //Debug.Log("Adding script!"); } AT.BeTransparent(); // get called every frame to reset the falloff } hits = Physics.RaycastAll(transform.position + new Vector3(0.0f, 1.5f, 0.0f), transform.forward, DistanceToPlayer); foreach (RaycastHit hit in hits) { //Debug.Log("Found object to fade!"); Renderer R = hit.collider.GetComponent <Renderer>(); if (R == null) { continue; // no renderer attached? go to next hit } AutoTransparent AT = R.GetComponent <AutoTransparent>(); if (AT == null) { // if no script is attached, attach one AT = R.gameObject.AddComponent <AutoTransparent>(); //Debug.Log("Adding script!"); } AT.BeTransparent(); // get called every frame to reset the falloff } hits = Physics.RaycastAll(transform.position + new Vector3(0.5f, 0.5f, 0.0f), transform.forward, DistanceToPlayer); foreach (RaycastHit hit in hits) { //Debug.Log("Found object to fade!"); Renderer R = hit.collider.GetComponent <Renderer>(); if (R == null) { continue; // no renderer attached? go to next hit } AutoTransparent AT = R.GetComponent <AutoTransparent>(); if (AT == null) { // if no script is attached, attach one AT = R.gameObject.AddComponent <AutoTransparent>(); //Debug.Log("Adding script!"); } AT.BeTransparent(); // get called every frame to reset the falloff } hits = Physics.RaycastAll(transform.position + new Vector3(1.0f, 0.5f, 0.0f), transform.forward, DistanceToPlayer); foreach (RaycastHit hit in hits) { //Debug.Log("Found object to fade!"); Renderer R = hit.collider.GetComponent <Renderer>(); if (R == null) { continue; // no renderer attached? go to next hit } AutoTransparent AT = R.GetComponent <AutoTransparent>(); if (AT == null) { // if no script is attached, attach one AT = R.gameObject.AddComponent <AutoTransparent>(); //Debug.Log("Adding script!"); } AT.BeTransparent(); // get called every frame to reset the falloff } hits = Physics.RaycastAll(transform.position + new Vector3(-0.5f, 0.5f, 0.0f), transform.forward, DistanceToPlayer); foreach (RaycastHit hit in hits) { //Debug.Log("Found object to fade!"); Renderer R = hit.collider.GetComponent <Renderer>(); if (R == null) { continue; // no renderer attached? go to next hit } AutoTransparent AT = R.GetComponent <AutoTransparent>(); if (AT == null) { // if no script is attached, attach one AT = R.gameObject.AddComponent <AutoTransparent>(); //Debug.Log("Adding script!"); } AT.BeTransparent(); // get called every frame to reset the falloff } hits = Physics.RaycastAll(transform.position + new Vector3(-1.0f, 0.5f, 0.0f), transform.forward, DistanceToPlayer); foreach (RaycastHit hit in hits) { //Debug.Log("Found object to fade!"); Renderer R = hit.collider.GetComponent <Renderer>(); if (R == null) { continue; // no renderer attached? go to next hit } AutoTransparent AT = R.GetComponent <AutoTransparent>(); if (AT == null) { // if no script is attached, attach one AT = R.gameObject.AddComponent <AutoTransparent>(); //Debug.Log("Adding script!"); } AT.BeTransparent(); // get called every frame to reset the falloff } } } }
void Update() { if (GlobalScript.Instance.MenuInputHandler.MenuEnabled) { return; } target.Theta += Utils.Instance.Player1.RightStickX() * rotationSpeed * Time.deltaTime * 60f; target.Phi += Utils.Instance.Player1.RightStickY() * rotationSpeed * Time.deltaTime * 60f; target.Radius -= Utils.Instance.Player1.DPadY() * zoomSpeed * Time.deltaTime * 30; if (GlobalScript.Instance.Driver.HasControl) { cameraToPlayer = Camera.transform.position - GlobalScript.Instance.Boat.transform.position; distanceToPlayer = cameraToPlayer.magnitude; cameraToPlayer.Normalize(); RaycastHit[] hits; // you can also use CapsuleCastAll() // TODO: setup your layermask it improve performance and filter your hits. hits = Physics.RaycastAll(Camera.transform.position + cameraToPlayer * 200, -cameraToPlayer, distanceToPlayer + 200); foreach (RaycastHit hit in hits) { if (hit.collider.tag == "boat" || hit.collider.tag == "TentacleRange") { continue; } Renderer R; if (hit.collider.tag == "Tentacle") { R = hit.collider.GetComponentInParent <Tentacle>().GetComponentInChildren <SkinnedMeshRenderer>().renderer; } else { R = hit.collider.renderer; } if (R == null) { //Search in children for renderers Renderer[] renderers = hit.collider.GetComponentsInChildren <MeshRenderer>(); foreach (MeshRenderer r in renderers) { AutoTransparent AT1 = r.GetComponent <AutoTransparent>(); if (AT1 == null) // if no script is attached, attach one { AT1 = r.gameObject.AddComponent <AutoTransparent>(); } AT1.BeTransparent(); // get called every frame to reset the falloff } renderers = hit.collider.GetComponentsInChildren <SkinnedMeshRenderer>(); foreach (SkinnedMeshRenderer r in renderers) { AutoTransparent AT1 = r.GetComponent <AutoTransparent>(); if (AT1 == null) // if no script is attached, attach one { AT1 = r.gameObject.AddComponent <AutoTransparent>(); } AT1.BeTransparent(); // get called every frame to reset the falloff } continue; } // no renderer attached? go to next hit // TODO: maybe implement here a check for GOs that should not be affected like the player AutoTransparent AT2 = R.GetComponent <AutoTransparent>(); if (AT2 == null) // if no script is attached, attach one { AT2 = R.gameObject.AddComponent <AutoTransparent>(); } AT2.BeTransparent(); // get called every frame to reset the falloff } } }