Answer the question
In order to leave comments, you need to log in
I am writing a script for the enemy in Unity, trying to implement the repulsion of the enemy when receiving damage, I ran into a problem who will help?
On the penultimate line, Unity writes that the "-" operator for operand types "Vector2" and "Vector3" is ambiguous.
What does this mean and can you help solve this problem?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ememy : MonoBehaviour
{
[SerializeField]
int lives;
[SerializeField]
float pushPower;
private Rigidbody2D rb;
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void Awake()
{
rb = GetComponent<Rigidbody2D>();
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.name == "AttackHitBox")
{
lives--;
PushAway(transform.position, 50f);
}
}
public void PushAway(Vector2 pushFrom, float pushPowe)
{
if (rb == null || pushPower == 0)
{
return;
}
var pushDirection = (pushFrom - transform.position).Normalize();
rb.AddForce(pushDirection * pushPower);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question