void OnCollisionEnter2D(Collision2D collision) { ThrowSpear actSpear = Enemy.GetComponent <ThrowSpear>(); if (collision.gameObject.tag == "Ground" || collision.gameObject.tag == "Block") { moveS = false; actSpear.hitGround = true; body2D.velocity = Vector2.zero; //Player.GetComponent<throwStone>().thrown = true; } }
// Update is called once per frame void Update() { Alien = GameObject.FindGameObjectWithTag("Alien"); Player = GameObject.FindGameObjectWithTag("Player"); ThrowSpear actSpear = Alien.GetComponent <ThrowSpear>(); if (spawned == false) { StoneP = GameObject.FindGameObjectWithTag("Spear"); if (StoneP) { target = new Vector2(StoneP.transform.position.x, StoneP.transform.position.y); Debug.Log("stonep" + StoneP); spawned = true; } } float step = speed * Time.deltaTime; if (StoneP) { StoneP.transform.position = Vector2.MoveTowards(StoneP.transform.position, transform.position, step); if (StoneP.transform.position == transform.position || reset == true) { StoneP.GetComponent <Rigidbody2D>().gravityScale = 0.5f; actSpear.reset = true; destruct = true; Debug.Log("Reset"); } if (destruct == true) { Player.GetComponent <throwStone>().spawned = false; Destroy(gameObject); Debug.Log("Destruct"); } } }
private void Start() { player = GameObject.FindGameObjectWithTag("Player"); throwSpearScript = GameObject.Find("speerspawn").GetComponent <ThrowSpear>(); }