Advertisement
JonneOpettaja

BouncerLeft.cs

May 10th, 2019
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.66 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class BouncerLeft : MonoBehaviour
  6. {
  7.     public float horizontalBounce = -15.0f;
  8.     public float upBounce = 10.0f;
  9.     GameObject player;
  10.  
  11.     // Start is called before the first frame update
  12.     void Start()
  13.     {
  14.         player = GameObject.FindGameObjectWithTag("Player");
  15.     }
  16.  
  17.     private void OnTriggerEnter2D(Collider2D collision)
  18.     {
  19.         player.GetComponent<Rigidbody2D>().velocity = -player.GetComponent<Rigidbody2D>().velocity;
  20.         player.GetComponent<Rigidbody2D>().AddForce(new Vector2(horizontalBounce, upBounce), ForceMode2D.Impulse);
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement