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

22 lines
697 B
C#
Raw Normal View History

2017-09-05 15:05:59 -05:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Explosion : MonoBehaviour {
2017-09-05 19:44:20 -05:00
public PlayerController player;
private float MAX_PLAYER_DIST = 3.0f;
2017-09-07 14:21:58 -05:00
private float EXPLOSION_FORCE = 15.0f;
2017-09-05 17:37:56 -05:00
2017-09-05 15:05:59 -05:00
void Start () {
2017-09-05 19:44:20 -05:00
Vector3 playerPos = player.transform.position;
float dist = (playerPos - transform.position).magnitude;
if (dist < MAX_PLAYER_DIST)
{
Rigidbody2D playerBody = player.GetComponent<Rigidbody2D>();
2017-09-07 00:50:49 -05:00
Vector2 force = (playerPos - transform.position).normalized * (MAX_PLAYER_DIST - dist) * EXPLOSION_FORCE;
2017-09-05 19:44:20 -05:00
playerBody.AddForce(force, ForceMode2D.Impulse);
}
2017-09-05 15:05:59 -05:00
}
}