От: | falcoware | https://falcoware.com/rus/ | |
Дата: | 15.05.24 13:05 | ||
Оценка: |
using FalcoEngine;
using System;
using System.Collections;
using System.Collections.Generic;
public class BallController : MonoBehaviour
{
GameController GC;
public AudioClip KickSound;
public bool IsGrounded;
public int Kicks=0;
public bool hasTouchedTheGround=false;
public int hasTouchedTheGroundInt= 0;
void Start()
{
GC = GameObject.Find("GameController").GetComponent<GameController>();
rigidbody.linearVelocity = Vector3.zero;
rigidbody.linearDamping = 0;
}
void Update()
{
if (transform.position.y > 0.9f)
{
IsGrounded = false;
if(hasTouchedTheGroundInt == 1)
{
hasTouchedTheGroundInt = 2;
}
}
else
{
IsGrounded = true;
Kicks = 0;
if (hasTouchedTheGround == false&&hasTouchedTheGroundInt == 0)
{
hasTouchedTheGround = true;
hasTouchedTheGroundInt = 1;
}
if(hasTouchedTheGroundInt == 2)
{
GC.EndOfGame();
}
}
}
public void Jump()
{
PlayKickSound();
rigidbody.AddForce(new Vector3(FalcoEngine.Random.Range(-0.4f, 0.4f), 1, 0) * 500);
Kicks += 1;
}
public void PlayKickSound()
{
audioSource.audioClip = KickSound;
audioSource.Play();
}
}