public GetPoint ( float distance ) : |
||
distance | float | Distance of the desired point along the path of the ray. |
Résultat |
static public int GetPoint(IntPtr l) { try{ UnityEngine.Ray2D self = (UnityEngine.Ray2D)checkSelf(l); System.Single a1; checkType(l, 2, out a1); UnityEngine.Vector2 ret = self.GetPoint(a1); pushValue(l, ret); return(1); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
// Update is called once per frame void Update() { if (!HeroController .GameOver ) { line.renderer .material .mainTextureOffset = new Vector2 (-Time.time, 0); Ray2D ray = new Ray2D (transform.position, transform.right); RaycastHit2D hit = Physics2D.Raycast (ray.origin, transform.right); line.SetPosition (0, ray.origin); if (hit.collider != null) { //gameObject.transform.FindChild("prarticleposition").transform.localPosition=new Vector2(1,0); particleposition.transform.position=hit.point; line.SetPosition (1, hit.point); if (hit.rigidbody) { hit.rigidbody .AddForceAtPosition (transform.right * 50, hit.point); } if (hit.collider.name == "Hero") { if (Time.time > lastHitTime + 1.25) { player.Vitals .TakeDamage(); lastHitTime = Time.time; } if (player.Vitals .Dead) { HeroController .GameOver=true; } } } else line.SetPosition (1, ray.GetPoint (10)); } //StopCoroutine ("FireLaser"); //StartCoroutine ("FireLaser"); }
//Coroutine to raycast then display lazer IEnumerator Firelazer() { lazer.enabled = true; //Enable LineRenderer while(Input.GetButton("Fire1")){ //Raycast for determining length of lazer Ray2D ray = new Ray2D(transform.position, transform.right); lazer.SetPosition(0, ray.origin); RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, lazerLength, lazerStoppers); //If the ray collides with something in the lazerStoppers, set the lazer's endpoint to the point of the collision if(hit){ lazer.SetPosition(1, hit.point); //If the ray hits an enemy, deal damage if(hit.collider.gameObject.tag == "enemy"){ hit.collider.gameObject.GetComponent<Enemy>().Hurt(50f); } } else //If no collision, set the lazer's endpoint to the lazerlength lazer.SetPosition(1, ray.GetPoint(lazerLength)); yield return null; } lazer.enabled = false; }
// // UPDATE FUNCTIONS START HERE // // Update is called once per frame public override void Update() { // new fall death code if (onGround ()) { float newGround = transform.position.y; if (fallCheck - 10 > newGround && !Dying) { CharacterBehavior.Dying = true; PlayerAnim.SetBool ("FallDeath", true); } fallCheck = newGround; } if (Dying) { transform.GetChild (4).gameObject.SetActive (true); } if (Input.GetKeyDown(KeyManagerScript.keys["AltJump"]) && !Input.GetKeyDown(KeyManagerScript.keys["Jump"]) || Input.GetKeyDown(KeyManagerScript.keys["Jump"]) && !Input.GetKeyDown(KeyManagerScript.keys["AltJump"])) { if (onGround()) { rb.AddForce(new Vector2(0, jumpspeed), ForceMode2D.Impulse); PlayerAnim.SetBool("Jump", true); } } base.Update (); //foreach (Transform t in GroundedEnds) //{ // //Debug.DrawLine(this.transform.position, t.position, Color.green); //} checkWall.origin = transform.position; rayhit = Physics2D.BoxCast(new Vector3(transform.position.x, transform.position.y + .5f, transform.position.z), BoxVec, 0.0f, checkWall.direction, checkWallDist, wallMasks); feet_check = Physics2D.Raycast(new Vector2(checkWall.origin.x , checkWall.origin.y - 1.2f), checkWall.direction, checkWallDist,checkMasks); //Debug.DrawRay(checkWall.origin,checkWall.direction,Color.green); //Debug.DrawRay(new Vector2(checkWall.origin.x , checkWall.origin.y - 1.2f), checkWall.direction); if (feet_check.collider != null) { //Debug.Log(feet_check.point); //Debug.Log(feet_check.collider.gameObject.transform.position.y); if (feet_check.collider.gameObject.tag != "impTrigger" && !(Input.GetKey(climb) || Input.GetKey(KeyManagerScript.keys["PushImp"]))) { RaycastHit2D check_empty = Physics2D.Raycast(checkWall.origin, checkWall.direction, checkWallDist, checkMasks); if (check_empty.collider == null && Mathf.Abs(Input.GetAxis("Horizontal")) > .5f) { //RaycastHit2D newLoc = Physics2D.Raycast( transform.position = new Vector3(transform.position.x, transform.position.y + .3f); } } } // Code for holding and throwing imps if (HoldingImp!="") { if(transform.childCount > 4) { Ray ray = ImpThrowCam.ScreenPointToRay(Input.mousePosition); mP = new Ray2D (new Vector2 (ray.origin.x, ray.origin.y-2.5f), new Vector2 (ray.direction.x, ray.direction.y)); if(Physics2D.Raycast (mP.origin,mP.direction,3.0f,IgnorePlayerLayer).collider == null) { transform.GetChild(5).transform.position = new Vector3(mP.GetPoint (2.0f).x,mP.GetPoint (2.0f).y,0.0f); } else { if (!transform.GetChild(5).GetComponent<ImpAI>().dead) { float Change = Physics2D.Raycast(mP.origin, mP.direction, 1.0f, IgnorePlayerLayer).distance; transform.GetChild(5).transform.position = new Vector3(mP.GetPoint(Change - 0.5f).x, mP.GetPoint(Change - 0.5f).y, 0.0f); } else { float Change = Physics2D.Raycast(mP.origin, mP.direction, 1.0f, IgnorePlayerLayer).distance; transform.GetChild(5).transform.position = new Vector3(mP.GetPoint(Change - 0.5f).x, mP.GetPoint(Change - 0.5f).y, 0.0f); } } } else { HoldingImp = ""; } } if (HoldingImp != "" && transform.GetChild(transform.childCount - 1).GetComponent<ImpAI>().DropKill == true) { HoldingImp = ""; Throwing = 0.01f; } // Code for recieving button input if ((Input.GetKeyDown (Summon) || Input.GetKeyDown(KeyManagerScript.keys["Summon"])) && (Input.GetKey(modifier) || Input.GetKey(KeyManagerScript.keys["Mod"])) && HoldingImp=="") { summon(true); // Summon a demon } if ((Input.GetKeyDown(Summon) || Input.GetKeyDown(KeyManagerScript.keys["Summon"])) && !(Input.GetKey(modifier) || Input.GetKey(KeyManagerScript.keys["Mod"])) && HoldingImp == "") { summon(false); } if (Input.GetKeyDown (ShiftRight)) { // Cycle the demon selection wheel to the left (NOW REVERSED!) if (--selected < 0) { selected = Demons.Length-1; } ImpSelect.GetComponent<Image> ().color = Demons [selected].GetComponent<SpriteRenderer> ().color; } if (Input.GetKeyDown(ShiftLeft) || Input.GetKeyDown(KeyManagerScript.keys["ChangeImp"])) { // Cycle the demon selection wheel to the right (reversed, CONSIDER REMOVING!) if (++selected >= Demons.Length) { selected = 0; } ImpSelect.GetComponent<Image> ().color = Demons [selected].GetComponent<SpriteRenderer> ().color; } if (Input.GetKey(killSelf) || Input.GetKey(KeyManagerScript.keys["KillYourself"])) { holdDown += Time.deltaTime; if (holdDown > 1.0f) { //OnDeath(); if (!CharacterBehavior.Dying){ PlayerAnim.SetBool("EnemyDeath", true); CharacterBehavior.Dying = true; transform.GetChild (4).gameObject.SetActive (true); } } } if (Input.GetKeyUp(killSelf) || Input.GetKeyUp(KeyManagerScript.keys["KillYourself"])) { holdDown = 0; } //if (Input.GetKeyDown(KeyCode.U)) //{ // Debug.Log("Imp Deaths"); // Debug.Log(ImpsKilled); // Debug.Log("Player Deaths"); // Debug.Log(TimesPlayerDied); //} //Grab an Imp or drop it if (Input.GetKeyDown(grabButton)) { if (HoldingImp != "" && HoldingImp != "stickImp") { HoldingImp = ""; Throwing = 0.01f; } else if (HoldingImp != "stickImp") { summon (true); } } if ((Input.GetMouseButtonDown (0) && !mouseDelay) || Throwing != 0.0f) { // THROW THE IMP! if(HoldingImp!="" && Throwing == 0.0f) { ThrowImp(ForceMult); } if(Throwing != 0.0f) { Throwing = 0.0f; if (HoldingImp == "stickImp") { transform.GetChild(5).GetComponent<StickImp>().Thrown = true; } ThrowImp(Throwing); } } if (Input.GetMouseButtonDown(1)) { if (HoldingImp != "") { Transform heldImp = transform.GetChild(5); if (heldImp != null) { ThrowImp (ForceMult); heldImp.GetComponent<ImpAI> ().KillImp (); GrabImp (heldImp.FindChild ("ImpTrigger").GetComponent<BoxCollider2D> ()); BoxCollider2D bc = heldImp.GetComponent<ImpAI> ().GetComponent<BoxCollider2D> (); heldImp.GetComponent<ImpAI> ().HalveCollider (bc, heldImp.GetComponent<ImpAI> ().heightChange); bc.offset = new Vector2 (bc.offset.x, bc.offset.y + (heldImp.GetComponent<ImpAI> ().heightChange / 2)); } } } if (mouseDelay) { mouseDelay = false; } if (Died) { Died = false; } }
void setDestinationCircle() { Vector3 point = MouseWorldPoint(); //if mouse is over no walk collider, move destination location out of contact with colliders in scene Collider2D overlap = Physics2D.OverlapCircle(point, selectedRadius, 1 << 10); if (overlap) { Ray2D ray = new Ray2D(overlap.transform.position, point-overlap.transform.position); float dist = Vector2.Distance(overlap.transform.position, point); while (overlap) { dist += 0.1f; point = ray.GetPoint(dist); overlap = Physics2D.OverlapCircle(point, selectedRadius, 1 << 10); } } //Draw Destination circle destinationCircle.MakeCircle(point, selectedRadius, 360); destinationCircle.active = true; pathGoal = point; }
void settarget() { float angle; Ray2D temp; switch (algotype) { case Algorithm.followmouse: if (Input.GetMouseButtonDown(0)) { Vector3 mousepos = Camera.main.ScreenToWorldPoint(Input.mousePosition); targetpos = mousepos; maketarget(); } break; case Algorithm.wander: Vector3 circle = Random.insideUnitCircle * 0.5f; angle = (transform.rotation.eulerAngles.z - 90 + 5) * Mathf.Deg2Rad; temp = new Ray2D(transform.position, new Vector2(Mathf.Cos(angle), Mathf.Sin(angle))); circle += (Vector3)temp.GetPoint(-2.0f); targetpos = circle; maketarget(); break; case Algorithm.arrive: targetpos = new Vector3(3.5f, 4f, 0f); maketarget(); break; case Algorithm.evade: if (evading != null) { float dy = evading.transform.position.y - transform.position.y; float dx = evading.transform.position.x - transform.position.x; angle = Mathf.Atan2(dy, dx); float dist = 1 / getdistto(dx, dy); temp = new Ray2D(transform.position, new Vector2(Mathf.Cos(angle), Mathf.Sin(angle))); targetpos = (Vector3)temp.GetPoint(-1 * dist); maketarget(); } break; case Algorithm.pathfollow: float mindist = float.MaxValue; int pos = 0; for (int i = 0; i < path.Count; ++i) { float distp = getdistto(path[i].x - transform.position.x, path[i].y - transform.position.y); if (distp < mindist) { pos = i; mindist = distp; } } targetpos = path[pos < 3 ? 0 : pos - 3]; maketarget(); break; } updaterotationfromposition(); if (loadnextlevel()) { doloadnextlevel(); } }
void makespeed(bool speedup) { if (speedupinstance != null && !speedup) { Destroy(speedupinstance); } if (speedupanim != null && speedup) { if (speedupinstance == null) { speedupinstance = (GameObject)Instantiate(speedupanim, new Vector3(transform.position.x, transform.position.y, 0), Quaternion.identity); } float angle = (transform.rotation.eulerAngles.z - 90) * Mathf.Deg2Rad; Ray2D temp = new Ray2D(transform.position, new Vector2(Mathf.Cos(angle),Mathf.Sin(angle))); //Debug.Log(temp.ToString() + ":" + angle.ToString()); speedupinstance.transform.position = temp.GetPoint(10 * currentplayerspeed * Time.deltaTime); speedupinstance.transform.rotation = transform.rotation; speedupinstance.GetComponent<SpriteRenderer>().color = myrenderer.color; } }
// methods static bool Ray2D_GetPoint__Single(JSVCall vc, int argc) { int len = argc; if (len == 1) { System.Single arg0 = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg); UnityEngine.Ray2D argThis = (UnityEngine.Ray2D)vc.csObj; JSApi.setVector2S((int)JSApi.SetType.Rval, argThis.GetPoint(arg0)); JSMgr.changeJSObj(vc.jsObjID, argThis); } return(true); }