void Update()
    {
        // タッチが開始されたら
        if (Input.touchCount > 0)
        {
            this.touch = Input.touches[0];
            // タッチ座標をVector2に変換
            this.touch_point = Camera.main.ScreenToWorldPoint(this.touch.position);

            if (touch.phase == TouchPhase.Began)
            {
                // Raycast(光線の出る位置, 光線の向き)
                this.hit = Physics2D.Raycast(this.touch_point, Vector2.zero);
                if (this.hit)
                {
                    GameObject selectedObject = this.hit.collider.gameObject;
                    switch (selectedObject.name)
                    {
                        case "Scal":
                            selectedObject.SendMessage("ShowsUp");
                            break;
                        case "ScalJumpsOut":
                            selectedObject.SendMessage("JumpsOut");
                            break;
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
    private void CastEffect(Vector3 hitPos, Vector3 hitNormal, RaycastHit2D hit)
    {
        //SimplePool.Spawn(bulletTrail.gameObject, firePoint.position, firePoint.rotation, true);
        /*Transform trail = Instantiate(bulletTrail, firePoint.position, firePoint.rotation) as Transform;
        LineRenderer lr = trail.GetComponent<LineRenderer>();

        if (lr != null) {
            lr.SetPosition(0, firePoint.position);
            lr.SetPosition(1, hitPos);
        }

        Destroy(trail.gameObject, 0.05f);
        */

        if (hitNormal != new Vector3(9999, 9999, 9999)) {
            if (hit.collider.tag == "Enemy") {
                GameObject hitEffect = Instantiate(bloodPrefab, hitPos, Quaternion.identity) as GameObject; // Quaternion.FromToRotation(Vector3.forward, hitNormal)
                Destroy(hitEffect, 0.2f);
            }
            else {
                GameObject hitEffect = Instantiate(hitPrefab, hitPos, Quaternion.FromToRotation(Vector3.forward, hitNormal)) as GameObject; // Quaternion.FromToRotation(Vector3.forward, hitNormal)
                Destroy(hitEffect, 1f);
            }
        }

        //Transform clone = SimplePool.Spawn(muzzleFlash.gameObject, firePoint.position, firePoint.rotation, true).transform;
        Transform clone = Instantiate(muzzleFlash, firePoint.position, firePoint.rotation) as Transform;
        clone.parent = firePoint;
        float muzzleSize = Random.Range(0.7f, 1f);
        clone.localScale = new Vector3(muzzleSize, muzzleSize, clone.localScale.z);
        clone.localPosition = new Vector3(clone.localPosition.x, clone.localPosition.y, clone.localPosition.z);
        Destroy(clone.gameObject, (1f / fireRate) / 2f);
        //SimplePool.Despawn(clone.gameObject);
    }
    static void RaycastHit2D_transform(JSVCall vc)
    {
        UnityEngine.RaycastHit2D _this = (UnityEngine.RaycastHit2D)vc.csObj;
        var result = _this.transform;

        JSMgr.datax.setObject((int)JSApi.SetType.Rval, result);
    }
Exemplo n.º 4
0
    void Update()
    {
        Clear();

        touches = Input.touches;
        foreach(Touch touch in touches)
        {
            Vector2 castPoint = Camera.main.ScreenToWorldPoint(touch.position);

            hitInfo = Physics2D.Linecast(castPoint, castPoint);
            if (hitInfo)
            {
                if (touch.phase == TouchPhase.Began)
                {
                    TouchEvent te = hitInfo.transform.GetComponent<TouchEvent>();
                    if (te) te.OnTouch();
                }

                int id = hitInfo.collider.GetHashCode();
                if (id == dPadUpId)
                    dPadUp = true;
                else if (id == dPadDownId)
                    dPadDown = true;
                else if (id == dPadLeftId)
                    dPadLeft = true;
                else if (id == dPadRightId)
                    dPadRight = true;
                else if (id == jumpId)
                    jump = true;
            }
        }
    }
        private bool CheckImages(RaycastHit2D[] hits)
        {
            foreach (RaycastHit2D hit in hits)
            {
                if (null != hit.collider)
                {
                    // Gather information about the image
                    SpriteRenderer spriteRenderer = hit.transform.GetComponent<SpriteRenderer>();
                    Texture2D tex = spriteRenderer.sprite.texture;
                    Vector3 v = hit.transform.worldToLocalMatrix.MultiplyPoint3x4(hit.point);
                    Bounds bounds = hit.transform.GetComponent<SpriteRenderer>().sprite.bounds;

                    // Convert to a UV System
                    float xPic = bounds.size.x - (v.x + bounds.extents.x);
                    float yPic = v.y + bounds.extents.y;

                    // Grab the alpha
                    Color color = tex.GetPixel((int)((xPic / bounds.size.x) * tex.width), (int)((yPic / bounds.size.y) * tex.height));
                    float alpha = color.a;

                    if (alphaCutoff < alpha)
                    {
                        return true;
                    }
                }
            }
            return false;
        }
Exemplo n.º 6
0
        protected void detectCollision(RaycastHit2D hit)
        {
            //if object is mirror
            positions.Add(new Vector3(hit.point.x, hit.point.y, 0));

            if (hit.collider.name == "Collector")
            {
                CollectorBehavior cb = hit.collider.gameObject.GetComponent<CollectorBehavior>();
                if (resetLast(cb.gameObject))
                {
                    cb.Activate(color, (EdgeCollider2D)hit.collider);
                }
            }
            //if Laser Switch
            else if (hit.collider.tag == "Laser Switch")
            {
                LaserSwitchBehavior ls = hit.collider.gameObject.GetComponent<LaserSwitchBehavior>();
                if (resetLast(ls.gameObject))
                {
                    ls.Activate(color);
                }
            }
            else
            {
                resetLast(hit.collider.gameObject);
            }
        }
Exemplo n.º 7
0
    public override void OnGazeStay(RaycastHit2D hit)
    {
        dwellTime = dwellTime + Time.deltaTime;
            GameObject.FindGameObjectWithTag("Dwellcursor").GetComponent<DwellTimeBar>().setDwelltime(dwellTime);
            if (dwellTime >= dwellTimeMax)
            {
                if (gameObject.tag == "Back")
                {
                    GameStateManager.Instance.startState("MainMenu2");

                }
                else if (gameObject.tag == "Screenshot")
                {
                    string screenshotFilename;
                    do
                    {
                        screenshotCount++;
                        screenshotFilename = "screenshot" + screenshotCount + ".png";

                    } while (System.IO.File.Exists(screenshotFilename));

                    Application.CaptureScreenshot(screenshotFilename);
                    GameStateManager.Instance.startState("MainMenu2");
                }
            }
    }
Exemplo n.º 8
0
    public void RightMove()
    {
        hit = Physics2D.Raycast(PlayerPosition.position, Right, distance1);

        if (hit.collider == null)
            GameObject.FindGameObjectWithTag("Player").transform.Translate(X, Y, 0);
    }
Exemplo n.º 9
0
    void NewRope(RaycastHit2D hit)
    {
        //need to check if object already exist;
        GameObject top = Instantiate(ropeTop);
        top.transform.position = new Vector3(hit.transform.position.x, hit.transform.position.y - hit.transform.GetComponent<SpriteRenderer>().bounds.size.y, 0.0f);

        float topSpriteHeight = top.GetComponent<SpriteRenderer>().bounds.size.y/2;
        float topSpriteWidth = top.GetComponent<SpriteRenderer>().bounds.size.x/2;
        Vector3 topLinePos = new Vector3(top.transform.position.x-.01f, top.transform.position.y-topSpriteHeight);

        //line.SetVertexCount(2);

        //line.enabled = true;

           	GameObject bottom = Instantiate(ropeBottom);
        bottom.transform.position = new Vector3(hit.transform.position.x, transform.position.y, 0.0f);
        float bottomSpriteHeight = bottom.GetComponent<SpriteRenderer>().bounds.size.y/2;
        float bottomSpritewidth = bottom.GetComponent<SpriteRenderer>().bounds.size.x/2;
        Vector3 botLinePos =  new Vector3(bottom.transform.position.x-.01f,bottom.transform.position.y+bottomSpriteHeight);

        line.SetPosition(0,botLinePos);

        line.SetPosition(1,topLinePos);
        Top = false;

        BoxCollider2D box = bottom.GetComponent<BoxCollider2D>();
        float boxsizeY = box.size.y;
        boxsizeY = Vector2.Distance(bottom.transform.position, top.transform.position);
        float offset = boxsizeY/2;
        box.offset = new Vector2(box.offset.x,offset);
        box.size = new Vector2(box.size.x, boxsizeY);
    }
Exemplo n.º 10
0
	void Update () {
		Rigidbody2D r = GetComponent<Rigidbody2D> ();
		r.velocity = new Vector2 (Input.GetAxis ("Horizontal") * speed, r.velocity.y);
		if (r.velocity.magnitude > 0.1f) {
			if (!isWalking) {
				StartCoroutine (Walk ());
			}
		}

		hit = Physics2D.Raycast (new Vector2 (transform.position.x, transform.position.y), Vector2.down);
		Debug.Log (Vector2.Distance(new Vector2 (transform.position.x, transform.position.y), hit.collider.transform.position));
		if (hit.distance < 1.9f) {
			isGrounded = true;
			Debug.Log ("On ground.");
		} else {
			isGrounded = false;
			Debug.Log("Off ground.");
		}

		if (isGrounded) {
			if (Input.GetKeyDown (jumpKey)) {
				r.velocity = new Vector2 (r.velocity.x, jumpSpeed);
			}
		}

		if (!isWalking) {
			GetComponent<SpriteRenderer> ().sprite = idleSprite;
		}
	}
	/*---------------------------------------------------- SWITCHABLE TOGGLE ----------------------------------------------------*/

    void SwitchableToggle(RaycastHit2D hit)
    {
        if (hit.collider.tag == "SwitchableClickArea")
        {
            GameObject hitObject = hit.transform.parent.gameObject;

			// Stop telling the player how to use the console if they do it once.
			if(playerControl.consoleTutorial)
			{
				dialogBox.EndDialogBox();
				playerControl.consoleTutorial = false;
			}

            //If powered
            if (hitObject.GetComponent<Power>().powered)
            { 
                if(hitObject.tag == "Door")
                {
                    if(!hitObject.GetComponent<DoorBehaviours>().DoorObstructed())
                        hitObject.GetComponent<PhotonView>().RPC("TogglePowered", PhotonTargets.AllBuffered, hit.transform.parent.tag);
                }

                else
                {
                    hitObject.GetComponent<PhotonView>().RPC("TogglePowered", PhotonTargets.AllBuffered, hit.transform.parent.tag);
                }
            }

            else//If not powered
            {
                if (powerManager.power >= hit.transform.parent.GetComponent<Power>().powerCost)
                    hitObject.GetComponent<PhotonView>().RPC("TogglePowered", PhotonTargets.AllBuffered, hit.transform.parent.tag);
            }
        }   
    }
Exemplo n.º 12
0
    //Function that takes in all of the RaycastHit2D's in the LinecastAll and checks to make sure the player is not obstructed
    //Only checks the tags of Gameobjects with 2D colliders.
    //Enemy and camerabounds colliders should not be taken into account when dealing with line of sight
    bool clearSight(RaycastHit2D[] hits)
    {
        foreach (RaycastHit2D hit in hits)
        {
            // ignore the enemy's own colliders (and other enemies) and the camera bounds
            if (hit.transform.tag == "Enemy")
                continue;

            if (hit.transform.tag == "camerabounds")
                continue;
            if (hit.transform.tag == "Untagged")
                continue;

            Debug.Log(hit.transform.tag);
            // if anything other than the player is hit then it must be between the player and the enemy's eyes (since the player can only see as far as the player)
            if (hit.transform.tag != "Player")
            {
                Debug.Log(hit.transform.tag);
                return false;
            }

            //if we get here then the player is not obstructed
            if(hit.transform.tag == "Player"){
                return true;
            }
        }

        return false;
    }
Exemplo n.º 13
0
    void Update()
    {
        if (ballDestroy >= MainMenu.ballAmt) {							// если шарики закончились то
            if (MainMenu.levelNum == 30) {								// если этот уровень последний то
                Application.LoadLevel("MainMenu");						// возвращаемся в гланое меню
            }

            Application.LoadLevel("EndLevel");							// переходим в меню выйгрыша
        }

        if (Input.GetMouseButtonDown(0)) {								// обрабатываем клик мыши
            RaycastHit2D aHit = new RaycastHit2D();						// инициализируем луч

            // проводим луч от камеры до места клика мышью
            aHit = Physics2D.Raycast(getCamera().ScreenToWorldPoint(Input.mousePosition), Vector2.zero);

            try {
                // если луч пресекает объект тег которого ball то
                if(Input.GetMouseButtonDown(0) && (aHit.transform.tag == "ball")) {
                    // если номер тапнутого шарика на один больше чем номур удаленного то
                    if (int.Parse(aHit.collider.gameObject.transform.FindChild("number").gameObject.GetComponent<TextMesh>().text) == ballDestroy + 1) {
                        MainMenu.gameTimer += 0.5f;
                        // проигрываем звук для тапнутого шарика
         						AudioSource.PlayClipAtPoint (ding, transform.position);
                        Destroy(aHit.collider.gameObject);				// удаляем этот объект
                        ballDestroy++;									// счетчик удалённых объектов
                        Score.score += 10;								// добавляем 10 очков за тапнутый шарик
                    }
                }
            } catch {
                // добавляем в исключение ошибку при клике в пустое пространство
                AudioSource.PlayClipAtPoint (play, transform.position); // звук для промаха
            }
        }
    }
	bool CheckIfBelow(GameObject obj) {

		Vector2 pos = transform.position;



		// number of ray checks
		int amt = 5;
		float[] rays = new float[amt];

		for(int i=0; i<amt; i++)
		{
			//float dir = Mathf.Sign(deltaY);
			float x = (pos.x + c.x - s.x) + 	/*creates the three collision rays, based on size of collision box */	s.x/2 * i; // left, center, and right ray colliders
			float y = pos.y + c.y +s.y/2 * -1; // bottom of collider
			
			ray = new Ray2D(new Vector2(x,y-1.6f), new Vector2(0, -1));
			
			// DEBUG RAYS //
			Debug.DrawRay(ray.origin, ray.direction);
			
			hit = Physics2D.Raycast(ray.origin, ray.direction, 1);
			
			if(hit != null && hit.collider != null && hit.collider.gameObject.name == obj.name)
			{
				return true;
			}
		}

		return false;
	}
 static public int constructor(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.RaycastHit2D o;
         o = new UnityEngine.RaycastHit2D();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Exemplo n.º 16
0
	void Update(){
		bottomMiddle = new Vector2 (transform.position.x, transform.position.y - 0.45f);
		raycastBottomMiddle = Physics2D.Raycast (bottomMiddle, Vector2.up, 0.05f, playerMask);
		Debug.DrawRay (bottomMiddle, Vector2.up, Color.blue, 0.05f);

		if (raycastBottomMiddle) {

			//displayingPrompt = false;
			if (!displayingPrompt) 
			{
				displayText (Color.white, "Press 'E'");
			}

			//spriteRenderer.sprite = half;
			if (Input.GetKey (KeyCode.E)) {
				//spriteRenderer.sprite = open;
				LoadLevel ();
			}
		} else
		{
			displayingPrompt = false;
		}

		//if (!raycastBottomMiddle)
		//	spriteRenderer.sprite = closed;
	}
Exemplo n.º 17
0
 void onCharacterControllerCollider(RaycastHit2D hit)
 {
     if (onControllerCollidedEvent != null)
     {
         onControllerCollidedEvent(hit);
     }
 }
Exemplo n.º 18
0
 // Update is called once per frame
 void Update()
 {
     if (GraviSwitchEnabled)
     {
         if (ButtonC.state)
         {
             ButtonC.state = false;
             GlobalStatics.GraviChange();
         }
         RaycastHit2D hit = new RaycastHit2D();
         Touch touch;
         for (int i = 0; i < Input.touchCount; ++i)
         {
             if (Input.GetTouch(i).phase.Equals(TouchPhase.Began))
             {
                 touch = Input.GetTouch(i);
                 //Ray ray = SecondaryCamera.ViewportPointToRay(new Vector3(touch.position.x, touch.position.y, 0));
                 hit = Physics2D.Raycast(SecondaryCamera.ScreenToWorldPoint(touch.position), Vector2.zero);
                 //Debug.Log("test");
                 //Debug.Log(hit.collider.name);
                 if (hit.collider != null)
                 {
                     //Debug.Log("STEVE!!");
                     hit.transform.gameObject.SendMessage("Select", SendMessageOptions.DontRequireReceiver);
                 }
             }
         }
     }
 }
Exemplo n.º 19
0
 RaycastHit2D[] combinebeams(RaycastHit2D[] A, RaycastHit2D[] B)
 {
     RaycastHit2D[] result = new RaycastHit2D[A.Length + B.Length];
     A.CopyTo(result, 0);
     B.CopyTo(result, A.Length);
     return result;
 }
Exemplo n.º 20
0
 protected override void OnImpact(RaycastHit2D hit, Collider2D other)
 {
     if(ShouldExplode(hit, other)) {
         Explode();
         return;
     }
 }
Exemplo n.º 21
0
	// Update is called once per frame
	void Update ()
    {
        Movement();
        //Debug.DrawLine(new Vector3(transform.position.x  + xPos, transform.position.y + yPos, transform.position.z), new Vector3(transform.position.x , transform.position.y + 0.24f, transform.position.z), Color.red);
        hit = Physics2D.Linecast(new Vector3(transform.position.x + xPos, transform.position.y + yPos, transform.position.z), new Vector3(transform.position.x + xPos, transform.position.y + yPos, transform.position.z));
        playerStanding = Physics2D.Linecast(new Vector3(transform.position.x, transform.position.y, transform.position.z), new Vector3(transform.position.x, transform.position.y, transform.position.z));
        if (playerStanding && playerStanding.collider.gameObject.tag == "end" && moved == true)
        {
            level.atEnd = true;
           //Debug.Log(level.atEnd);
        }
        else
        {
            level.atEnd = false;
            //Debug.Log(level.atEnd);
        }


        if (playerStanding && playerStanding.collider.gameObject.tag == "start" && moved == true && level.currentlevel != 0)
            level.atStart = true;
        if (hit)
        {
            if (hit.collider.gameObject.tag == "Tree" && Input.GetKeyDown(KeyCode.Space))
                Debug.Log("I clicked On a tree");

        }

    }
Exemplo n.º 22
0
        /// <summary>
        /// Read the data using the reader.
        /// </summary>
        /// <param name="reader">Reader.</param>
        public override object Read(ISaveGameReader reader)
        {
            UnityEngine.RaycastHit2D raycastHit2D = new UnityEngine.RaycastHit2D();
            foreach (string property in reader.Properties)
            {
                switch (property)
                {
                case "centroid":
                    raycastHit2D.centroid = reader.ReadProperty <UnityEngine.Vector2> ();
                    break;

                case "point":
                    raycastHit2D.point = reader.ReadProperty <UnityEngine.Vector2> ();
                    break;

                case "normal":
                    raycastHit2D.normal = reader.ReadProperty <UnityEngine.Vector2> ();
                    break;

                case "distance":
                    raycastHit2D.distance = reader.ReadProperty <System.Single> ();
                    break;

                case "fraction":
                    raycastHit2D.fraction = reader.ReadProperty <System.Single> ();
                    break;
                }
            }
            return(raycastHit2D);
        }
Exemplo n.º 23
0
    private Rigidbody2D rb2D; //The Rigidbody2D component attached to this object.

    #endregion Fields

    #region Methods

    //Move returns true if it is able to move and false if not.
    //Move takes parameters for x direction, y direction and a RaycastHit2D to check collision.
    protected bool Move(int xDir, int yDir, out RaycastHit2D hit)
    {
        //Store start position to move from, based on objects current transform position.
        Vector2 start = transform.position;

        // Calculate end position based on the direction parameters passed in when calling Move.
        Vector2 end = start + new Vector2(xDir, yDir);

        //Disable the boxCollider so that linecast doesn't hit this object's own collider.
        boxCollider.enabled = false;

        //Cast a line from start point to end point checking collision on blockingLayer.
        hit = Physics2D.Linecast(start, end, blockingLayer);

        //Re-enable boxCollider after linecast
        boxCollider.enabled = true;

        //Check if anything was hit
        if (hit.transform == null)
        {
            //If nothing was hit, start SmoothMovement co-routine passing in the Vector2 end as destination
            StartCoroutine(SmoothMovement(end));

            //Return true to say that Move was successful
            return true;
        }

        //If something was hit, return false, Move was unsuccesful.
        return false;
    }
Exemplo n.º 24
0
    public void Update()
    {
        command = inputHandler.HandleInput();
        
        if (command != null)
        {
            command.Execute(this);
        }

        Vector2 vectorR  = new Vector2(transform.position.x+0.13f, transform.position.y);
        Vector2 vectorL  = new Vector2(transform.position.x-0.13f, transform.position.y);
        Vector2 vectorD  = new Vector2(transform.position.x      , transform.position.y-0.17f);
        Vector2 vectorDL = new Vector2(transform.position.x-0.12f, transform.position.y-0.17f);
        Vector2 vectorDR = new Vector2(transform.position.x+0.12f, transform.position.y-0.17f);
        
        hitR = Physics2D.Raycast(vectorR  , Vector2.right);
        hitL = Physics2D.Raycast(vectorL  , Vector2.left );
        hitD = Physics2D.Raycast(vectorD  , Vector2.down );
        hitDL = Physics2D.Raycast(vectorDL, Vector2.down );
        hitDR = Physics2D.Raycast(vectorDR, Vector2.down );
            
        distanceR  = Mathf.Abs(hitR.point.x  - vectorR.x);
        distanceL  = Mathf.Abs(hitL.point.x  - vectorL.x);
        distanceD  = Mathf.Abs(hitD.point.y  - vectorD.y);
        distanceDL = Mathf.Abs(hitDL.point.y - vectorDL.y);
        distanceDR = Mathf.Abs(hitDR.point.y - vectorDR.y);
        
        SetAnimation();

        canJump  = (distanceDL <= 0.01f) || (distanceDR <= 0.01f);
        canTotem = (distanceD  <= 0.01f);
        
    }
Exemplo n.º 25
0
    //Casting a list of raylist at different angles along the field of angle vision.
    void CastRays()
    {
        numRays = fovAngle * quality;
        currentAngle = fovAngle / -2;

        hits.Clear();

        for (int i = 0; i < numRays; i++)
        {
            //Determine the angle at which the raycast should be shooting from.
            Vector3 temp = Quaternion.AngleAxis(currentAngle, transform.up) * transform.forward;
            direction = new Vector2(temp.x, temp.y);

            hit = new RaycastHit2D();
            //Checks if raycast is hitting an object between 0.1 < z < 1
            hit = Physics2D.Raycast(new Vector2(transform.position.x, transform.position.y), direction, fovMaxDistance, cullingMask, 0.1f, 1);
            if (!hit)
            {
                //create the raycast up until it is flush with the object. Which makes the guard not see "behind" walls.
                hit.point = new Vector2(transform.position.x, transform.position.y) + (direction * fovMaxDistance);
            }

            hits.Add(hit);

            //to check every raycast that was made in the field of view.
            currentAngle += 1f / quality;
        }
    }
Exemplo n.º 26
0
		/// <summary>
		/// 	Initializes a new instance of the Hit2DWrapper struct.
		/// </summary>
		/// <param name="hit">Hit.</param>
		/// <param name="origin">Origin.</param>
		/// <param name="radius">Radius.</param>
		/// <param name="direction">Direction.</param>
		/// <param name="distance">Distance.</param>
		public Hit2DWrapper(RaycastHit2D hit, Vector3 origin, float radius, Vector3 direction, float distance)
		{
			m_Hit = hit;
			m_Origin = origin;
			m_Direction = direction.normalized;
			m_Distance = distance;
		}
Exemplo n.º 27
0
 void Update()
 {
     RaycastHit2D hit = new RaycastHit2D();
     Touch touch;
     if (Application.platform == RuntimePlatform.Android)
     {
         for (int i = 0; i < Input.touchCount; ++i)
         {
             if (Input.GetTouch(i).phase.Equals(TouchPhase.Began))
             {
                 touch = Input.GetTouch(i);
                 hit = Physics2D.Raycast(cam.ScreenToWorldPoint(touch.position), Vector2.zero);
                 if (hit.collider != null)
                 {
                     hit.transform.gameObject.SendMessage("doAction", SendMessageOptions.DontRequireReceiver);
                 }
             }
         }
     }
     else
     {
         if (Input.GetKeyDown(KeyCode.Mouse0))
         {
             hit = Physics2D.Raycast(cam.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
             if (hit.collider != null)
             {
                 hit.transform.gameObject.SendMessage("doAction", SendMessageOptions.DontRequireReceiver);
             }
         }
     }
 }
Exemplo n.º 28
0
    void Update()
    {
        if (drawLine)
            CodingClub.Render_line(this.gameObject, joint.gameObject);

        CodingClub.Level_Reload("enemy");

        hit = CodingClub.Mouse_pos();

        if (hit.collider != null && hit.transform.gameObject == this.gameObject && !played)
        {
            if (Input.GetKeyDown(KeyCode.Mouse0))
                follow = true;

            if (Input.GetKeyUp(KeyCode.Mouse0))
            {
                played = true;
                follow = false;
                drawLine = false;
                CodingClub.Shot(this.gameObject, joint.gameObject);
                CodingClub.Hide_line(this.gameObject);
            }
        }

        if (Input.GetKey(KeyCode.Mouse0) && follow)
            CodingClub.Follow_mouse(this.gameObject);

        if (CodingClub.is_moving(played, this.gameObject))
        {
            CodingClub.restart_player(this.gameObject, oldPos);
            drawLine = true;
            played = false;
        }
    }
Exemplo n.º 29
0
    bool DestroyPoint(RaycastHit2D hit, bool isAlienTarget)
    {
        var point = hit.point;
        var sprite = m_spriteBuilder.Sprite;
        var bunkerScale = sprite.rect.width;
        var spriteRect = sprite.rect;
        var translatedX = (point.x - transform.position.x) + .5f;
        var projectileX = Mathf.RoundToInt (spriteRect.x + translatedX * bunkerScale);

        var halfWidth = HorizontalPixelsDestroyedPerShoot / 2;
        var projectileWidth = HorizontalPixelsDestroyedPerShoot;
        var bunkerHeight = Mathf.RoundToInt (spriteRect.height);
        var hitPixelsByShoot = ((bunkerHeight / MaxShootSupportedInPoint) * projectileWidth) + projectileWidth;

        var hitPixelsCount = 0;

        if (isAlienTarget) {
            for (int pixelY = 0; pixelY < bunkerHeight; pixelY++) {
                DestroyHorizontalPizels (pixelY, projectileX, halfWidth, hitPixelsByShoot, ref hitPixelsCount);
            }
        } else {
            for (int pixelY = bunkerHeight; pixelY > 0; pixelY--) {
                DestroyHorizontalPizels (pixelY, projectileX, halfWidth, hitPixelsByShoot, ref hitPixelsCount);
            }
        }

        m_spriteBuilder.Rebuild();

        return hitPixelsCount >= MinimumHitPixelsToBlockProjectile;
    }
Exemplo n.º 30
0
        /// <summary>
        /// Handles a Danmaku collision. Only ever called with Danmaku that pass the filter.
        /// </summary>
        /// <param name="danmaku">the danmaku that hit the collider.</param>
        /// <param name="info">additional information about the collision</param>
        protected override void DanmakuCollision(Danmaku danmaku,
                                                 RaycastHit2D info) {
            if (affected.Contains(danmaku))
                return;
            if (rotationMode == RotationType.Reflection)
            {
                Vector2 normal = info.normal;
                Vector2 direction = danmaku.direction;
                danmaku.Direction = direction -
                                    2 * Vector2.Dot(normal, direction) * normal;
                affected.Add(danmaku);
                return;
            }

            float baseAngle = angle;
            switch (rotationMode) {
                case RotationType.Relative:
                    baseAngle += danmaku.Rotation;
                    break;
                case RotationType.Object:
                    if (Target != null) {
                        baseAngle += DanmakuUtil.AngleBetween2D(
                                                                danmaku.Position,
                                                                Target.position);
                    } else {
                        Debug.LogWarning(
                                         "Trying to direct at an object but no Target object assinged");
                    }
                    break;
                case RotationType.Absolute:
                    break;
            }
            danmaku.Rotation = baseAngle;
            affected.Add(danmaku);
        }
Exemplo n.º 31
0
    // Update is called once per frame
    void Update()
    {
        liike = new Vector3(5f, 0f, 0f);
        hit = Physics2D.Raycast(transform.position, Vector3.left, 5f);
        hit1 = Physics2D.Raycast(transform.position, Vector3.right, 5f);

        Debug.DrawRay(transform.position, Vector3.left);
        Debug.DrawRay(transform.position, Vector3.right);

                if ((hit) && hit.collider.gameObject.tag == "hero" )
                {

                    transform.Translate(Vector3.right * 2f*Time.deltaTime);

                }

                if ((hit1) && hit1.collider.gameObject.tag == "hero" )
                {

                    transform.Translate(Vector3.left * 2f * Time.deltaTime);

                }

                Debug.Log(hit);
    }
Exemplo n.º 32
0
    void Shoot()
    {
        line.enabled = true;
        ParticlesOnLaserBegin.enableEmission = true;
        line.SetPosition(0, line.transform.position);
        //	if (GameController.shooting && atualCooldown < 0) {
        hit = Physics2D.Raycast(new Vector2(line.transform.position.x, line.transform.position.y), objective, ShootRange, 1 << LayerMask.NameToLayer("PlayerTarget"));
        if (hit != null && hit.collider != null)
        {
            Debug.Log("Hitting");
            hitPosition = new Vector3(hit.point.x, hit.point.y, this.transform.position.z - 1);
            line.SetPosition(1, hitPosition);
            Enemy enemy = hit.collider.gameObject.GetComponent<Enemy>();
            DamageOverSec = Damage * Time.deltaTime;
          //      particleOnLaserEnd.enableEmission = true;
          //      particleOnLaserEnd.transform.position = new Vector3(hitPosition.x, hitPosition.y, particleOnLaserEnd.transform.position.z);
        }
        else
        {
            hitPosition = new Vector3(line.transform.position.x + (objective.normalized.x * ShootRange), line.transform.position.y + (objective.normalized.y * ShootRange), this.transform.position.z);
            line.SetPosition(1, hitPosition);
            //EmitParticleOnLaser (posSpawn.transform.position, hitPosition);
           // particleOnLaserEnd.enableEmission = false;
            //		line.SetPosition (1, new Vector3 (0, 0, 3000));

        }
        int dist = (int)Vector2.Distance(line.transform.position, hitPosition) / 5;
        /*    if (ParticlesOnLaser.particleCount < dist * 10 || ParticlesOnLaser.particleCount < 3)
        {
            EmitParticleOnLaser(posSpawn.position, hitPosition);
        }*/
        //	ParticlesOnLaser.emissionRate = particlesOnLaserMax * (ParticlesOnLaser.transform.localScale.x / ShootRange);
    }
Exemplo n.º 33
0
    void Raycast()
    {
        Vector2 interactPoint = new Vector2();
        switch (direction)
        {
            case Directions.North:
                interactPoint = rBody.position + new Vector2(0, interactLength);
                break;
            case Directions.East:
                interactPoint = rBody.position + new Vector2(interactLength, 0);
                break;
            case Directions.South:
                interactPoint = rBody.position + new Vector2(0, -interactLength);
                break;
            case Directions.West:
                interactPoint = rBody.position + new Vector2(-interactLength, 0);
                break;
        }

        Debug.DrawLine(rBody.position, interactPoint, Color.green);
        interact = Physics2D.Linecast(rBody.position, interactPoint, 1 << LayerMask.NameToLayer("Interactive"));

        if (interact)
        {
            interactable = Physics2D.Linecast(rBody.position, interactPoint, 1 << LayerMask.NameToLayer("Interactive"));
            if (Input.GetKeyDown(KeyCode.E))
            {
//                Weights script = interactable.collider.gameObject.GetComponent<Weights>;
            }
        }
    }
Exemplo n.º 34
0
 static public int set_normal(IntPtr l)
 {
     UnityEngine.RaycastHit2D o = (UnityEngine.RaycastHit2D)checkSelf(l);
     UnityEngine.Vector2      v;
     checkType(l, 2, out v);
     o.normal = v;
     setBack(l, o);
     return(0);
 }
Exemplo n.º 35
0
 /// <summary>
 /// Write the specified value using the writer.
 /// </summary>
 /// <param name="value">Value.</param>
 /// <param name="writer">Writer.</param>
 public override void Write(object value, ISaveGameWriter writer)
 {
     UnityEngine.RaycastHit2D raycastHit2D = (UnityEngine.RaycastHit2D)value;
     writer.WriteProperty("centroid", raycastHit2D.centroid);
     writer.WriteProperty("point", raycastHit2D.point);
     writer.WriteProperty("normal", raycastHit2D.normal);
     writer.WriteProperty("distance", raycastHit2D.distance);
     writer.WriteProperty("fraction", raycastHit2D.fraction);
 }
Exemplo n.º 36
0
    static public int set_distance(IntPtr l)
    {
        UnityEngine.RaycastHit2D o = (UnityEngine.RaycastHit2D)checkSelf(l);
        float v;

        checkType(l, 2, out v);
        o.distance = v;
        setBack(l, o);
        return(0);
    }
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.RaycastHit2D o;
         o = new UnityEngine.RaycastHit2D();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 38
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.RaycastHit2D o;
         o = new UnityEngine.RaycastHit2D();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
// methods

    static bool RaycastHit2D_CompareTo__RaycastHit2D(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 1)
        {
            UnityEngine.RaycastHit2D arg0    = (UnityEngine.RaycastHit2D)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
            UnityEngine.RaycastHit2D argThis = (UnityEngine.RaycastHit2D)vc.csObj;                JSApi.setInt32((int)JSApi.SetType.Rval, (System.Int32)(argThis.CompareTo(arg0)));
            JSMgr.changeJSObj(vc.jsObjID, argThis);
        }

        return(true);
    }
Exemplo n.º 40
0
 static public int CompareTo(IntPtr l)
 {
     try{
         UnityEngine.RaycastHit2D self = (UnityEngine.RaycastHit2D)checkSelf(l);
         UnityEngine.RaycastHit2D a1;
         checkType(l, 2, out a1);
         System.Int32 ret = self.CompareTo(a1);
         pushValue(l, ret);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
 static void RaycastHit2D_distance(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.RaycastHit2D _this = (UnityEngine.RaycastHit2D)vc.csObj;
         var result = _this.distance;
         JSApi.setSingle((int)JSApi.SetType.Rval, (System.Single)(result));
     }
     else
     {
         System.Single            arg0  = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg);
         UnityEngine.RaycastHit2D _this = (UnityEngine.RaycastHit2D)vc.csObj;
         _this.distance = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
 static void RaycastHit2D_normal(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.RaycastHit2D _this = (UnityEngine.RaycastHit2D)vc.csObj;
         var result = _this.normal;
         JSApi.setVector2S((int)JSApi.SetType.Rval, result);
     }
     else
     {
         UnityEngine.Vector2      arg0  = (UnityEngine.Vector2)JSApi.getVector2S((int)JSApi.GetType.Arg);
         UnityEngine.RaycastHit2D _this = (UnityEngine.RaycastHit2D)vc.csObj;
         _this.normal = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
    static int get_normal(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.RaycastHit2D obj = (UnityEngine.RaycastHit2D)o;
            UnityEngine.Vector2      ret = obj.normal;
            ToLua.Push(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index normal on a nil value"));
        }
    }
    static int get_rigidbody(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.RaycastHit2D obj = (UnityEngine.RaycastHit2D)o;
            UnityEngine.Rigidbody2D  ret = obj.rigidbody;
            ToLua.PushSealed(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index rigidbody on a nil value"));
        }
    }
    static int get_collider(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.RaycastHit2D obj = (UnityEngine.RaycastHit2D)o;
            UnityEngine.Collider2D   ret = obj.collider;
            ToLua.Push(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index collider on a nil value"));
        }
    }
    static int get_fraction(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.RaycastHit2D obj = (UnityEngine.RaycastHit2D)o;
            float ret = obj.fraction;
            LuaDLL.lua_pushnumber(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index fraction on a nil value"));
        }
    }
    static int CompareTo(IntPtr L)
    {
        try
        {
            ToLua.CheckArgsCount(L, 2);
            UnityEngine.RaycastHit2D obj  = (UnityEngine.RaycastHit2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.RaycastHit2D));
            UnityEngine.RaycastHit2D arg0 = StackTraits <UnityEngine.RaycastHit2D> .Check(L, 2);

            int o = obj.CompareTo(arg0);
            LuaDLL.lua_pushinteger(L, o);
            ToLua.SetBack(L, 1, obj);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
    static int set_fraction(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.RaycastHit2D obj = (UnityEngine.RaycastHit2D)o;
            float arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
            obj.fraction = arg0;
            ToLua.SetBack(L, 1, obj);
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index fraction on a nil value"));
        }
    }
    static int set_normal(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.RaycastHit2D obj  = (UnityEngine.RaycastHit2D)o;
            UnityEngine.Vector2      arg0 = ToLua.ToVector2(L, 2);
            obj.normal = arg0;
            ToLua.SetBack(L, 1, obj);
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index normal on a nil value"));
        }
    }
Exemplo n.º 50
0
 static int GetRayEx(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 5);
         Game obj = (Game)ToLua.CheckObject <Game>(L, 1);
         UnityEngine.Vector2 arg0 = ToLua.ToVector2(L, 2);
         UnityEngine.Vector2 arg1 = ToLua.ToVector2(L, 3);
         float arg2 = (float)LuaDLL.luaL_checknumber(L, 4);
         int   arg3 = (int)LuaDLL.luaL_checknumber(L, 5);
         UnityEngine.RaycastHit2D o = obj.GetRayEx(arg0, arg1, arg2, arg3);
         ToLua.PushValue(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemplo n.º 51
0
 static public int get_distance(IntPtr l)
 {
     UnityEngine.RaycastHit2D o = (UnityEngine.RaycastHit2D)checkSelf(l);
     pushValue(l, o.distance);
     return(1);
 }
 static bool RaycastHit2D_op_Implicit__RaycastHit2D_to_Boolean(JSVCall vc, int argc)
 {
     UnityEngine.RaycastHit2D arg0 = (UnityEngine.RaycastHit2D)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
     JSApi.setBooleanS((int)JSApi.SetType.Rval, (System.Boolean)((System.Boolean)arg0));
     return(true);
 }
Exemplo n.º 53
0
 static public int get_centroid(IntPtr l)
 {
     UnityEngine.RaycastHit2D o = (UnityEngine.RaycastHit2D)checkSelf(l);
     pushValue(l, o.centroid);
     return(1);
 }
Exemplo n.º 54
0
 static public int get_collider(IntPtr l)
 {
     UnityEngine.RaycastHit2D o = (UnityEngine.RaycastHit2D)checkSelf(l);
     pushValue(l, o.collider);
     return(1);
 }
Exemplo n.º 55
0
 static public int get_fraction(IntPtr l)
 {
     UnityEngine.RaycastHit2D o = (UnityEngine.RaycastHit2D)checkSelf(l);
     pushValue(l, o.fraction);
     return(1);
 }
 static int _CreateUnityEngine_RaycastHit2D(IntPtr L)
 {
     UnityEngine.RaycastHit2D obj = new UnityEngine.RaycastHit2D();
     ToLua.PushValue(L, obj);
     return(1);
 }
Exemplo n.º 57
0
 static public int get_normal(IntPtr l)
 {
     UnityEngine.RaycastHit2D o = (UnityEngine.RaycastHit2D)checkSelf(l);
     pushValue(l, o.normal);
     return(1);
 }
Exemplo n.º 58
0
 static public int get_rigidbody(IntPtr l)
 {
     UnityEngine.RaycastHit2D o = (UnityEngine.RaycastHit2D)checkSelf(l);
     pushValue(l, o.rigidbody);
     return(1);
 }
Exemplo n.º 59
0
 static public int get_transform(IntPtr l)
 {
     UnityEngine.RaycastHit2D o = (UnityEngine.RaycastHit2D)checkSelf(l);
     pushValue(l, o.transform);
     return(1);
 }