本文整理汇总了C#中UnityEngine.RaycastHit类的典型用法代码示例。如果您正苦于以下问题:C# RaycastHit类的具体用法?C# RaycastHit怎么用?C# RaycastHit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RaycastHit类属于UnityEngine命名空间,在下文中一共展示了RaycastHit类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: HitManager
//private int MaskLayer; // excludes hits to only objects here.
//private float RayDistance;
public HitManager(Camera asSeenByCamera)
{
Hit = new RaycastHit();
//RayDistance = Mathf.Infinity;
//MaskLayer = Physics.kDefaultRaycastLayers;
SetHitCamera(asSeenByCamera);
}
开发者ID:cassab,项目名称:Decorato_Sketching,代码行数:9,代码来源:HitManager.cs
示例2: FixedUpdate
//Fixed Update is called every __ seconds, Edit Project Settings Time Fixed TimeStamp
//Movement
void FixedUpdate()
{
if (Input.GetKey (KeyCode.UpArrow)){
GetComponent<Rigidbody>().AddForce(GetComponent<Transform>().forward *2f, ForceMode.VelocityChange);
}
if (Input.GetKey (KeyCode.LeftArrow)) {
GetComponent<Rigidbody>().AddForce(GetComponent<Transform>().right *2f, ForceMode.VelocityChange);
//transform.Rotate(new Vector3(0f,-5f,0f));
}
if (Input.GetKey (KeyCode.RightArrow)) {
GetComponent<Rigidbody>().AddForce(GetComponent<Transform>().right *-2f, ForceMode.VelocityChange);
//transform.Rotate(new Vector3(0f,5f,0f));
}
//transform.position = GetComponent<Transform>
Ray ray = new Ray (transform.position, -Vector3.up);
//to know where and what the raycast hit , we have to store that impact info
RaycastHit rayHit = new RaycastHit (); //Blank Container for Info
if (Physics.Raycast (ray, out rayHit, 1.1f))
{
if (Input.GetKey (KeyCode.RightShift))
{
GetComponent<Rigidbody> ().AddForce (new Vector3 (0f, 5000f, 0f), ForceMode.Acceleration);
Debug.Log (rayHit.point);
//Destroy (rayHit.collider.gameObject);
}
}
}
开发者ID:hejohnny,项目名称:FourSquare,代码行数:32,代码来源:Player2Controller.cs
示例3: FixedUpdate
void FixedUpdate()
{
// foreach (GameObject, mouseObject in GameManager.allTheMice, GameManager.alltheMice) {
for (int i=0; i<GameManager.allTheMice.Count; i++) {
GameObject mouseTransform = GameManager.allTheMice[i];
Vector3 directionToMouse = mouseTransform.transform.position - transform.position;
float angle = Vector3.Angle (directionToMouse, transform.forward);
if (angle < 90f) {
Ray catRay = new Ray (transform.position, directionToMouse);
RaycastHit catRayHitInfo = new RaycastHit ();
if (Physics.Raycast (catRay, out catRayHitInfo, 30f)) {
Debug.DrawRay (catRay.origin, catRay.direction);
if (catRayHitInfo.collider.tag == "Mouse") {
if (catRayHitInfo.distance < 3f) {
GameManager.allTheMice.Remove(mouseTransform);
Destroy (mouseTransform);
eating.Play();
}
else {
rbodyCat.AddForce (directionToMouse.normalized * 1000f);
boss1.Play();
}
}
}
}
}
}
开发者ID:LeaTalbot,项目名称:AI-Simulation,代码行数:32,代码来源:Cat.cs
示例4: Update
// Update is called once per frame
void Update()
{
Ray playerRay = new Ray (transform.position + new Vector3(0f, 30, 0f), transform.forward);
RaycastHit hit = new RaycastHit();
if (Physics.Raycast (playerRay, out hit, 100f)) {
//npcTextPrefab.text = "LOL";
Debug.DrawRay ( playerRay.origin, playerRay.direction * hit.distance, Color.blue);
//if the item the raycast is hitting the TV
if (hit.transform.gameObject.tag == "TV") {
//if player has object required to interact with TV then...
if (girlItems.ContainsKey ("Scissors")) {
if (Input.GetKeyDown (KeyCode.G)) {
Destroy (hit.transform.gameObject);
Destroy (transform.Find ("Scissors").gameObject);
girlItems.Remove ("Scissors");
//Destroy
}
}
}
if ( hit.transform.gameObject.tag == "toilet" ) {
if (girlItems.ContainsKey("Cake")) {
if ( Input.GetKeyDown (KeyCode.E) ) {
Destroy (hit.transform.gameObject);
Destroy (transform.Find ("Cake").gameObject);
girlItems.Remove ("Cake");
}
}
}
}
}
开发者ID:neemar,项目名称:Final-Project,代码行数:31,代码来源:ObjectInteractions.cs
示例5: DoPolish
public override void DoPolish()
{
vectorToPlayer = Camera.main.transform.position - transform.position - Vector3.Project (Camera.main.transform.position - transform.position,Vector3.up);
vectorToPlayer.Normalize ();
Vector3 cameraRelativeVelocity = Vector3.Project (rigidbody.velocity ,Camera.main.transform.right);
if(interpolateCamera){
//Focus camera on ball. Ideally this code would be in a proper CameraController class. However, for the purposes of this exercise, we are keeping all relevant code in one single file.
Camera.main.transform.rotation = Quaternion.Lerp (Camera.main.transform.rotation,Quaternion.LookRotation(transform.position + cameraRelativeVelocity*cameraHorizontalOffsetPerSpeed + Camera.main.transform.up*cameraVerticalOffSet - Camera.main.transform.position,Vector3.up),cameraInterpolationStrength*Time.deltaTime);
}else{
//Focus camera on ball.
Camera.main.transform.rotation = Quaternion.LookRotation(transform.position + cameraRelativeVelocity*cameraHorizontalOffsetPerSpeed+ Camera.main.transform.up*cameraVerticalOffSet - Camera.main.transform.position,Camera.main.transform.up);
}
if(follow){
Vector3 desiredPosition = transform.position + vectorToPlayer*distanceToPlayer + Vector3.up*height;
Vector3 dir = desiredPosition - transform.position;
float distanceToCamera = dir.magnitude;
dir.Normalize ();
RaycastHit hit = new RaycastHit();
if (Physics.Raycast (transform.position, dir,out hit,distanceToCamera + distanceToWall,cameraCollisionLayers )) {
Vector3 point = hit.point - dir*distanceToWall;
desiredPosition = point + Vector3.up*(1 - (point - transform.position).magnitude/distanceToPlayer)*10;
}
Camera.main.transform.position =Vector3.Lerp (Camera.main.transform.position ,desiredPosition,cameraMovementStrength*Time.deltaTime);
}
}
开发者ID:juanraigada,项目名称:CET-PROTOTYPE,代码行数:30,代码来源:CameraLookController.cs
示例6: add_node
public void add_node(Vector3 pos, int prev_node_id, RaycastHit hit)
{
int current_selected_node = get_selected_node ();
if (current_selected_node >= 0) {
int tmp_id = nodes.Count;
GameObject tmp = (GameObject)Instantiate (node_template, pos, Quaternion.identity);
tmp.gameObject.GetComponent<node>().node_const(pos, tmp_id ,prev_node_id, true);
tmp.gameObject.GetComponent<node>().is_base_node = false;
tmp.gameObject.transform.rotation = Quaternion.FromToRotation(Vector3.down, hit.normal);
nodes.Add (tmp);
//nodes[tmp_id].gameObject.GetComponent<node>().node_const(pos ,tmp_id, get_selected_node (), true);
last_added_wp = tmp_id;
//MANAGE RES -> connect to res with node
foreach (GameObject r in GameObject.FindGameObjectsWithTag(vars.res_tag))
{
if (!r.GetComponent<ressource>().is_node_connected && r.GetComponent<ressource>().circle_holder.gameObject.GetComponent<selection_circle>().is_point_in_circle(pos) && r.GetComponent<ressource>().circle_holder.gameObject.GetComponent<selection_circle>().enabled)
{
r.gameObject.GetComponent<ressource>().is_node_connected = true;
get_node_with_intern_node_id(tmp_id).connected_with_res = true;
get_node_with_intern_node_id(tmp_id).connected_res_id = r.GetComponent<ressource>().ressource_id;
get_node_with_intern_node_id(tmp_id).node_pos = r.gameObject.GetComponent<ressource>().ressource_pos;
GameObject.Find("RES_SELECTION_UI").GetComponent<res_selection_ui_manager>().update_res_selection_ui();
}
}
Instantiate(scout_ant_prefab);
} else {
Debug.LogError("NODE KONNTE NICHT ERSTELLT WERDEN KA KEINER SELEKTOER WURDE");
}
}
开发者ID:ColdBass,项目名称:Antboss,代码行数:34,代码来源:pathmanager.cs
示例7: Update
// Update is called once per frame
void Update()
{
var ray = new Ray();
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit = new RaycastHit();
if (Input.GetMouseButtonDown(0))
if (collider.Raycast(ray, out hit, 100.0f))
{
this.startPos = this.parent.transform.position;
this.timer = 0;
this.onMove = true;
this.superScript.updateY((int)Mathf.Abs(_position/7));
}
if (this.onMove)
{
this.moveOn();
this.timer += Time.deltaTime * this._speed;
}
if (this.timer >= 1) this.onMove = false;
if (collider.Raycast(ray, out hit, 100.0f))
{
Debug.DrawLine(ray.origin, hit.point, Color.green, 1);
// texte.material.color = new Color(01 / 255, 47 / 255, 98 / 2);
}
else
{
// texte.material.color = Color.white;
}
}
开发者ID:paulineEsgi,项目名称:BomberMat,代码行数:34,代码来源:TabFleetScript.cs
示例8: Start
// Use this for initialization
void Start()
{
float rad = 0;
float ang = 0;
for (int i = 0; i < Random.Range(50,100); ++i)
{
rad = Random.Range(0.0f, 250.0f);
ang = Random.Range(0.0f, Mathf.PI * 2.0f);
RaycastHit hit = new RaycastHit();
Vector3 top = new Vector3(Mathf.Cos(ang) * rad + 1600, 1000, Mathf.Sin(ang) * rad + 600);
Ray ray = new Ray(top, new Vector3(0, -1, 0));
Physics.Raycast(ray, out hit);
GameObject nodeInst = Instantiate(node, hit.point, new Quaternion()) as GameObject;
Node nodeInstNode = nodeInst.GetComponent<NodeTest>().node;
nodeInstNode.cultyness = Random.Range(-100, 100);
nodeInstNode.farmyness = Random.Range(-100, 100);
nodeInstNode.mournyness = Random.Range(-100, 100);
nodeInstNode.religyness = Random.Range(-100, 100);
nodeInstNode.socialness = Random.Range(-100, 100);
nodeInstNode.wanderyness = Random.Range(-100, 100);
if (Random.Range(0,5) <= 1)
{
nodeInstNode.sleepyness = true;
}
}
}
开发者ID:Hologuardian,项目名称:GlobalGameJam2016,代码行数:31,代码来源:NodePopulateTest.cs
示例9: Raycasting
// Checks for a collision with each part of each player and returns the number of the player that was hit last
int Raycasting(Ray ray)
{
RaycastHit info = new RaycastHit();
foreach (Transform child in Player1)
{
ray = new Ray(transform.position, child.position - transform.position);
if (Physics.Raycast (ray, out info, 2.3f) && info.transform == Player1)
return 1;
}
foreach (Transform child in Player2)
{
ray = new Ray (transform.position, child.position - transform.position);
if (Physics.Raycast (ray, out info, 2.3f) && info.transform == Player2)
return 2;
}
foreach (Transform child in Player3)
{
ray = new Ray (transform.position, child.position - transform.position);
if (Physics.Raycast (ray, out info, 2.3f) && info.transform == Player3)
return 3;
}
foreach (Transform child in Player4)
{
ray = new Ray (transform.position, child.position - transform.position);
if (Physics.Raycast (ray, out info, 2.3f) && info.transform == Player4)
return 4;
}
return lastHit;
}
开发者ID:johnward2,项目名称:Four_Square,代码行数:30,代码来源:Ball.cs
示例10: Update
// Update is called once per frame
void Update()
{
RaycastHit hit = new RaycastHit ();
if (this.collider.Raycast (new Ray (Camera.main.ScreenToWorldPoint (Input.mousePosition), Camera.main.transform.forward), out hit, 1000.0f)) {
last = down;
down = Input.GetMouseButtonDown (0) || Input.GetMouseButton (0);
Vector3 position = this.transform.position + new Vector3 (0f, 6.0f - this.transform.localScale.y / 2.0f, 0.0f);
position.y = Camera.main.ScreenToWorldPoint (Input.mousePosition).y;
Vector3 posmouse = Camera.main.ScreenToWorldPoint (Input.mousePosition);
if (jumper != null)
posmouse.z = jumper.transform.position.z;
if (!last && down) {
if (remember.Item == null && jumper != null && (posmouse - jumper.transform.position).magnitude < 1.0) {
remember.Item = jumper;
jumper = null;
} else if (remember.Item != null && jumper != null && (posmouse - jumper.transform.position).magnitude < 1.0) {
GameObject temp = jumper;
jumper = remember.Item;
remember.Item.transform.position = position;
remember.Item.rigidbody.velocity = Vector3.zero;
remember.Item = temp;
} else if (remember.Item != null && jumper == null) {
remember.Item.transform.position = position;
remember.Item.rigidbody.velocity = Vector3.zero;
remember.Item = null;
jumper = remember.Item;
}
}
}
}
开发者ID:SHyx0rmZ,项目名称:gamejam,代码行数:33,代码来源:Dropzone.cs
示例11: GetPositionNextToHoveredTile
/// <summary>
/// Returns the position next to the side you pressed on.
/// </summary>
public static Vector3 GetPositionNextToHoveredTile () {
Event e = Event.current;
Ray ray = SceneView.lastActiveSceneView.camera.ScreenPointToRay(new Vector3(
e.mousePosition.x, Screen.height - e.mousePosition.y - 36, 0)); //Upside-down and offset a little because of menus
RaycastHit hit = new RaycastHit();
if (Physics.Raycast(ray, out hit, 1000.0f)) {
if (hit.collider.gameObject.GetComponent<ChunkObjectData>()) {
return hit.collider.gameObject.transform.position + hit.normal;
}
else {
Debug.LogWarning("The location you want to paint at is not on the same chunk as selected.");
}
}
else {
return new Vector3(0, 9000, 0);
}
return new Vector3(0, 9000, 0);
}
开发者ID:KevinBreurken,项目名称:VME,代码行数:35,代码来源:VMEGlobal.cs
示例12: TakeHit
public void TakeHit(float damage, RaycastHit hit) {
health -= damage;
if (health <= 0 && !dead) {
Die();
}
}
开发者ID:ardaWill,项目名称:Create-a-Game-Source,代码行数:7,代码来源:LivingEntity.cs
示例13: FixedUpdate
void FixedUpdate()
{
foreach (GameObject cat in GameManager.catList) {
Vector3 directionToCat = cat.transform.position - transform.position;
//if ( Vector3.Angle(transform.forward, directionToCat) < 180f) {
Ray butterflyRay = new Ray(transform.position, directionToCat);
RaycastHit butterflyRayHitInfo = new RaycastHit();
if (Physics.Raycast(butterflyRay, out butterflyRayHitInfo, 100f)) {
//Debug.DrawRay (butterflyRay.origin, directionToCat * butterflyRayHitInfo.distance, Color.red);
//Debug.Log ("see");
if (butterflyRayHitInfo.collider.tag == "Cat") {
//Debug.Log ("see");
Ray ray_corner_check = new Ray(transform.position, -transform.forward);
// if cat is in front && within front detection range
// if not cornered
// turn around
if ( Vector3.Angle(transform.forward, directionToCat) < frontal_detection_cone && butterflyRayHitInfo.distance < frontal_detection_range ) {
//Debug.Log ("see");
if (!Physics.Raycast(ray_corner_check, check_cornered_distance)) {
transform.Rotate(0f, 180f, 0f);
}
}
// if cat is within circular detection range
// panic
if ( butterflyRayHitInfo.distance < circular_detection_range) {
//Debug.Log("panic");
GetComponent<Rigidbody>().AddForce(-directionToCat.normalized * panic_speed);
}
}
//}
}
}
}
开发者ID:Azcryte,项目名称:Game-dev---AI-simulation,代码行数:33,代码来源:Butterfly.cs
示例14: OnGUI
void OnGUI()
{
//message to the player if he is dead
if(dead){
GUI.Box(new Rect(200, 300, 190, 50), "You died..Respawn in.. "+displaytime);
}
//raycast for close units and shopping
RaycastHit hit = new RaycastHit();
if(playertarget&attackrange){
if(Physics.Linecast(playertarget.transform.position, attackrange.transform.position, out hit)){
shop shop=(shop)hit.transform.GetComponent("shop");
orderai ai=(orderai)hit.transform.GetComponent("orderai");
if(ai){
if(ai.enableaiorder){}
else{
GUI.Box(new Rect(200, 300, 150, 50), "Press E To Give Orders!");
if(Input.GetKey(KeyCode.E)) ai.enableaiorder=true;
}
}
if(shop){
if(shop.menuactive){}
else{
GUI.Box(new Rect(200, 300, 150, 50), "Press E To Shop!");
if(Input.GetKey(KeyCode.E)) shop.menuactive=true;
}
}
}
}
}
开发者ID:ungureanu88,项目名称:Hoarder,代码行数:33,代码来源:freefly.cs
示例15: Update
void Update()
{
if(Input.GetMouseButtonDown( 0 ))
{
if(cam)
{
ray = cam.ScreenPointToRay( Input.mousePosition );
}else{
ray = Camera.main.ScreenPointToRay( Input.mousePosition );
}
RaycastHit rayHit = new RaycastHit();
if( Physics.Raycast(ray, out rayHit, 100f) )
{
if(rayHit.transform.gameObject.layer == 11)
{
rayHit.transform.gameObject.GetComponent<LoadSceneButton>().StartLoading();
}else if( rayHit.transform.gameObject.layer == 12)
{
rayHit.transform.gameObject.GetComponent<OtherButton>().SetClicked();
rayHit.transform.gameObject.GetComponent<OtherButton>().Execute();
}
}
}
}
开发者ID:ramsesoriginal,项目名称:Bzzt,代码行数:27,代码来源:ClickBehaviour.cs
示例16: Move
public void Move(RaycastHit hit){
this.gameObject.GetComponent<Animator> ().SetBool ("Walking", true);
this.gameObject.GetComponent<NavMeshAgent> ().destination = hit.point;
//Debug.Log ("Stop Working");
CurTask = Task.Moving;
}
开发者ID:Roseluck,项目名称:AIRTS2,代码行数:7,代码来源:TankScript.cs
示例17: Update
// Update is called once per frame
void Update()
{
if ( Input.GetKeyDown( KeyCode.Space ) ) {
// a for() loop iterates through a collection and does stuff to each item
foreach ( Fish fish in fishList ) {
// fish.destination = Vector3.zero;
fish.SetNewDestination( Vector3.zero );
}
}
// the usual way to generate a ray
// Ray ray = new Ray( transform.position, transform.forward );
// generate a ray based on our mouse position on our screen
if ( Input.GetMouseButton( 0 ) ) {
Ray ray = Camera.main.ScreenPointToRay( Input.mousePosition );
RaycastHit rayHit = new RaycastHit();
if ( Physics.Raycast( ray, out rayHit, 1000f ) ) {
// Debug.Log( rayHit.point );
foreach ( Fish fish in fishList ) {
fish.SetNewDestination( rayHit.point );
}
}
}
}
开发者ID:radiatoryang,项目名称:gamedev_july2013,代码行数:27,代码来源:FishGod.cs
示例18: Update
void Update()
{
if (Input.GetKey(KeyCode.L)) {
if (!L_downflag) {
L_downflag=true;
if (dlight.shadows==LightShadows.None) {
dlight.shadows=LightShadows.Soft;
} else {
dlight.shadows=LightShadows.None;
}
}
} else {
L_downflag=false;
}
Material mat=grass.renderer.material;
Collider col=grass.collider;
Ray ray = new Ray(rigidbody.position+Vector3.up, -Vector3.up);
RaycastHit hit=new RaycastHit();
if (col.Raycast(ray, out hit, 100f)) {
float dmp=Mathf.Clamp(1-(rigidbody.position.y-0.3042075f)/0.35f,0,1);
Vector4 pos=new Vector4(hit.textureCoord.x, hit.textureCoord.y, dmp*dmp, 0);
mat.SetVector("_ballpos", pos);
rigidbody.drag=dmp*1.0f;
float v=rigidbody.velocity.magnitude*5.0f;
dmp/=(v<1) ? 1 : v;
rigidbody.angularDrag=dmp*1.0f;
}
}
开发者ID:gordonklarson,项目名称:Perfect-Soccer,代码行数:30,代码来源:SoccerBall.cs
示例19: Update
// Update is called once per frame
void Update()
{
//create raycast
Ray playerRay = new Ray (transform.position, transform.forward);
RaycastHit hit = new RaycastHit();
if (Physics.Raycast (playerRay, out hit, 10f)) {
Debug.DrawRay ( playerRay.origin, playerRay.direction * hit.distance, Color.red);
if (hit.transform.gameObject.tag == "Throwable2") {
npcTextPrefab3.text = "Press K to pick scissors up";
//if player one presses G
if (holdingObject2 == false && Input.GetKeyDown (KeyCode.K)) {
npcTextPrefab3.text = "Press K to throw";
guy2.instance.picked2= true;
holdingObject2 = true;
hit.transform.parent = transform;
}
else if (holdingObject2 == true && Input.GetKeyDown (KeyCode.K)) {
holdingObject2 = false;
guy2.instance.donezo2= true;
hit.transform.parent = null;
hit.transform.GetComponent<Rigidbody>().constraints &= ~RigidbodyConstraints.FreezePosition;
}
hit.transform.GetComponent<Rigidbody>().AddForce (hit.transform.forward * 2000);
}
else {
npcTextPrefab3.text = "";
}
}
}
开发者ID:neemar,项目名称:Final-Project,代码行数:30,代码来源:throwobjelev222.cs
示例20: Update
// Update is called once per frame
void Update()
{
//click to place cat or mouse
Ray mouseRay = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit mouseRayHit = new RaycastHit();
//Left click instantiates cat
if (Input.GetMouseButtonDown (0))
{
if (Physics.Raycast (mouseRay, out mouseRayHit, 100f))
{
GameObject newCatClick = (GameObject) Instantiate (catPrefab, mouseRayHit.point, Quaternion.Euler (0f, 0f, 0f));
listOfMice.Add (newCatClick);
}
}
//Right click instantiates mouse
if (Input.GetMouseButtonDown (1))
{
if (Physics.Raycast (mouseRay, out mouseRayHit, 100f))
{
GameObject newMouseClick = (GameObject) Instantiate (mousePrefab, mouseRayHit.point, Quaternion.Euler (0f, 0f, 0f));
listOfMice.Add (newMouseClick);
}
}
}
开发者ID:duhmichael,项目名称:CatAndMouse,代码行数:28,代码来源:GameManager.cs
注:本文中的UnityEngine.RaycastHit类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论