21 lines
621 B
C#
21 lines
621 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[RequireComponent(typeof(Rigidbody))]
|
|
public class Trampoline : MonoBehaviour
|
|
{
|
|
private float _power = 10f;
|
|
[SerializeField] private Material[] jumpMaterial;
|
|
|
|
private void OnCollisionEnter(Collision collision)
|
|
{
|
|
if (collision.gameObject.CompareTag("Ball"))
|
|
{
|
|
collision.gameObject.GetComponent<Rigidbody>().AddForce(Vector2.up * _power, ForceMode.Impulse);
|
|
|
|
collision.gameObject.GetComponent<Renderer>().material = jumpMaterial[Random.Range(0, jumpMaterial.Length)];
|
|
}
|
|
}
|
|
}
|