// Update is called once per frame void Update() { if (Input.touchCount > 0 || Input.GetMouseButton(1)) { RaycastHit hit; Ray ray; if (Input.touchCount > 0) { ray = Camera.main.ScreenPointToRay(Input.touches[0].position); } else { ray = Camera.main.ScreenPointToRay(Input.mousePosition); } if (Physics.Raycast(ray, out hit)) { if (hit.collider.gameObject.GetComponent <McBlock>() != null) { _mcBlock = hit.collider.gameObject.GetComponent <McBlock>(); Vector3 _a = _mcBlock.transform.InverseTransformPoint(hit.point) + (Vector3.one * 0.5f); McBlock.mcPoint _b = _mcBlock.getPoint(Mathf.RoundToInt(_a.x * _mcBlock.dimX), Mathf.RoundToInt(_a.y * _mcBlock.dimY), Mathf.RoundToInt(_a.z * _mcBlock.dimZ)); Debug.Log("Block: " + _mcBlock.name + " was clicked at point: " + _b.px + "," + _b.py + "," + _b.pz); } } } }
// Update is called once per frame void Update() { if(Input.touchCount>0 || Input.GetMouseButton(1)) { RaycastHit hit; Ray ray; if(Input.touchCount>0) ray = Camera.main.ScreenPointToRay(Input.touches[0].position ); else ray = Camera.main.ScreenPointToRay(Input.mousePosition); if(Physics.Raycast (ray, out hit )) { if(hit.collider.gameObject.GetComponent<McBlock>() != null ) { _mcBlock = hit.collider.gameObject.GetComponent<McBlock>(); Vector3 _a = _mcBlock.transform.InverseTransformPoint(hit.point) + (Vector3.one * 0.5f); McBlock.mcPoint _b = _mcBlock.getPoint( Mathf.RoundToInt(_a.x * _mcBlock.dimX), Mathf.RoundToInt(_a.y * _mcBlock.dimY), Mathf.RoundToInt(_a.z * _mcBlock.dimZ)); Debug.Log("Block: " + _mcBlock.name + " was clicked at point: " + _b.px + "," + _b.py + "," + _b.pz); } } } }
void Update() { if (materialsSet == false && blockMaterial != null) { foreach (McBlock _block in blocks) { if (_block.renderer != null) { _block.renderer.material = blockMaterial; materialsSet = true; } } } if (Input.touchCount > 0 || Input.GetMouseButton(0)) { RaycastHit hit; Ray ray; if (Input.touchCount > 0) { ray = Camera.main.ScreenPointToRay(Input.touches[0].position); } else { ray = Camera.main.ScreenPointToRay(Input.mousePosition); } if (Physics.Raycast(ray, out hit)) { if (hit.collider.gameObject.GetComponent <McBlock>() != null) { _mcBlock = hit.collider.gameObject.GetComponent <McBlock>(); Vector3 _a = _mcBlock.transform.InverseTransformPoint(hit.point) + (Vector3.one * 0.5f); McBlock.mcPoint _b = _mcBlock.getPoint(Mathf.RoundToInt(_a.x * _mcBlock.dimX), Mathf.RoundToInt(_a.y * _mcBlock.dimY), Mathf.RoundToInt(_a.z * _mcBlock.dimZ)); //Debug.Log("Block: " + _mcBlock.name + " was clicked at point: " + _b.px + "," + _b.py + "," + _b.pz + " - "+ _b.i ()); int _x = Mathf.RoundToInt(_a.x * _mcBlock.dimX); int _y = Mathf.RoundToInt(_a.y * _mcBlock.dimY); int _z = Mathf.RoundToInt(_a.z * _mcBlock.dimZ); SetValue(_mcBlock, _x, _y, _z, _b.i() * 0.98f); Debug.DrawLine(Camera.main.transform.position, hit.point); GameObject _exlplodePrefab = Resources.Load("Explosivo/Explosion") as GameObject; GameObject.Instantiate(_exlplodePrefab, hit.point, Quaternion.identity); //_mcBlock.RequiresUpdate = true; } } } }
void Update() { if(materialsSet == false && blockMaterial!=null) { foreach(McBlock _block in blocks) if(_block.renderer!=null) { _block.renderer.material = blockMaterial; materialsSet = true; } } if(Input.touchCount>0 || Input.GetMouseButton(0)) { RaycastHit hit; Ray ray; if(Input.touchCount>0) ray = Camera.main.ScreenPointToRay(Input.touches[0].position ); else ray = Camera.main.ScreenPointToRay(Input.mousePosition); if(Physics.Raycast (ray, out hit )) { if(hit.collider.gameObject.GetComponent<McBlock>() != null ) { _mcBlock = hit.collider.gameObject.GetComponent<McBlock>(); Vector3 _a = _mcBlock.transform.InverseTransformPoint(hit.point) + (Vector3.one * 0.5f); McBlock.mcPoint _b = _mcBlock.getPoint( Mathf.RoundToInt(_a.x * _mcBlock.dimX), Mathf.RoundToInt(_a.y * _mcBlock.dimY), Mathf.RoundToInt(_a.z * _mcBlock.dimZ)); //Debug.Log("Block: " + _mcBlock.name + " was clicked at point: " + _b.px + "," + _b.py + "," + _b.pz + " - "+ _b.i ()); int _x = Mathf.RoundToInt(_a.x * _mcBlock.dimX); int _y = Mathf.RoundToInt(_a.y * _mcBlock.dimY); int _z = Mathf.RoundToInt(_a.z * _mcBlock.dimZ); SetValue(_mcBlock, _x, _y, _z, _b.i () * 0.98f); Debug.DrawLine(Camera.main.transform.position, hit.point); GameObject _exlplodePrefab = Resources.Load("Explosivo/Explosion") as GameObject; GameObject.Instantiate(_exlplodePrefab, hit.point, Quaternion.identity); //_mcBlock.RequiresUpdate = true; } } } }