using UnityEngine; using System.Collections; public class BulletBeam : MonoBehaviour {
public Texture farTexture; public Texture nearTexture; private Texture texture;
public static bool isChange = false; void Start () { Screen.showCursor = true; texture = farTexture; }
void Update () { changeTexture(); myRay(); }
void myRay () { CharacterController controller = GetComponent<CharacterController>();
Vector3 position = new Vector3(Screen.width/2 - (texture.width>>1) , Screen.height/2-(texture.height>>1),10.0f);
Ray ray = Camera.main.ScreenPointToRay(position); Debug.DrawRay (ray.origin, ray.direction * 10, Color.blue);
//LayerMask layerMaskPlayers = 1 << LayerMask.NameToLayer("Enemy"); //LayerMask layerMaskTerraim = 1 << //LayerMask.NameToLayer("Terrain"); //LayerMask FinaMask = (layerMaskTerraim.value | //layerMaskPlayers.value);
RaycastHit hit; if(Input.GetMouseButtonDown(0)||Input.GetMouseButton(0)) { if(Physics.Raycast(ray,out hit)) { if(hit.collider.name == "Cube") { Instantiate(particle_metal,hit.point,Quaternion.identity); hit.rigidbody.AddForceAtPosition(ray.direction,hit.transform.position,ForceMode.Impulse); }
}
}
}
public void changeTexture() { if(isChange) texture = nearTexture; else texture = farTexture; }
void OnGUI () { Rect rect = new Rect(Screen.width/2 - (texture.width>>1) , Screen.height/2-(texture.height>>1) ,texture.width,texture.height);
GUI.DrawTexture(rect,texture); } } |