public override void BeAttacked(SceneGameObject attacker) { var my = GetPosition(); var other = attacker.GetPosition(); var offset = other - my; offset.Normalize(); int yRotation = 0; if (offset.x > 0) { if (offset.y > 0 && offset.y > offset.x) { yRotation = 270; } else if (offset.y < 0 && -offset.y > offset.x) { yRotation = 90; } } else { if (offset.y > 0 && offset.y > -offset.x) { yRotation = 270; } else if (offset.y < 0 && -offset.y > -offset.x) { yRotation = 90; } else { yRotation = 180; } } var original = m_GameObject.transform.localEulerAngles; var oldy = original.y; original.y = yRotation; Debug.Log("BeAttacked:x=" + offset.x + ",y=" + offset.y + ",rotation=" + yRotation + ",oldy=" + oldy); m_GameObject.transform.localEulerAngles = original; m_IsAttack = true; }
public virtual void BeAttacked(SceneGameObject attacker) { }
public virtual void Attack(SceneGameObject target) { target.BeAttacked(this); }