This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
project-undercover/Game 1/Assets/Scripts/Explosion.cs
2017-09-07 14:21:58 -05:00

21 lines
697 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Explosion : MonoBehaviour {
public PlayerController player;
private float MAX_PLAYER_DIST = 3.0f;
private float EXPLOSION_FORCE = 15.0f;
void Start () {
Vector3 playerPos = player.transform.position;
float dist = (playerPos - transform.position).magnitude;
if (dist < MAX_PLAYER_DIST)
{
Rigidbody2D playerBody = player.GetComponent<Rigidbody2D>();
Vector2 force = (playerPos - transform.position).normalized * (MAX_PLAYER_DIST - dist) * EXPLOSION_FORCE;
playerBody.AddForce(force, ForceMode2D.Impulse);
}
}
}