ITHUB\Student c638464fe3 Add project
Added new project
2024-09-09 11:10:25 +03:00

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)];
}
}
}