You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
837 B
C#
30 lines
837 B
C#
2 months ago
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
||
|
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace Lofelt.NiceVibrations
|
||
|
{
|
||
|
public class BallPusher : MonoBehaviour
|
||
|
{
|
||
|
public float Force = 5f;
|
||
|
public BallDemoBall TargetBall;
|
||
|
protected Vector2 _direction;
|
||
|
|
||
|
protected virtual void OnTriggerEnter2D(Collider2D collider)
|
||
|
{
|
||
|
if (collider.gameObject != TargetBall.gameObject)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
_direction = (collider.transform.position - this.transform.position).normalized;
|
||
|
_direction.y = 1f;
|
||
|
collider.attachedRigidbody.velocity = Vector2.zero;
|
||
|
collider.attachedRigidbody.AddForce(_direction * Force);
|
||
|
TargetBall.HitPusher();
|
||
|
}
|
||
|
}
|
||
|
}
|