unity2d

Collision callback function not called

一笑奈何 提交于 2019-11-28 13:11:28
i am bloody beginner with Unity and i am currently working on a 2D Brawler. The movement works perfectly but my colliders don't do what they should... I want to detect if two GameObjects Collide (Spear and Player2) and if the collide Player2s healthPoints should decrease by Spears AttackDamage. The names of the GameObjects are also their tags. The Spears Prefab has following configuration: SpriteRendered(Material Sprites-Default), BoxCollider2D(Material None Physics Material 2D, IsTrigger(not activated), UsedByEffector(also not activated) Rigidbody2D(Kinematic, None Material, Simulated

Wait for a coroutine to finish before moving on with the function C# Unity

半世苍凉 提交于 2019-11-28 01:59:40
I was working on making a unit move through a grid in Unity2d. I got the movement to work without problems. I would want the function MovePlayer to wait until the coroutine is finished before moving on, so the program will wait until the player has finished the movement before issuing more orders. Here is my code: public class Player : MonoBehaviour { public Vector3 position; private Vector3 targetPosition; private float speed; void Awake () { speed = 2.0f; position = gameObject.transform.position; targetPosition = position; GameManager.instance.AddPlayerToList(this); //Register this player