Cześć otóż robię grę w unity. Planuję bardziej rozbudować tę produkcję ale nie do końca rozumiem C#. Na chwilę obecną potrzebuje pomocy w dopracowaniu systemu Double-Jumpa. Codzi o to że chcę aby po wjechaniu oraz zderzeniu się z Colliderami np jakiejś jakiejś monety uruchamiało to skrypt który doda do postaci umiejętność double-jumpa. Sam skok mam zaprogramowany ale nie wiem jak zmieniać jego wartość innym skryptem żeby właśnie z jednego skoku wartość zmieniała się na dwa skoki. Dorzucam kod do systemu poruszania się oraz do systemu tej monety.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ogcontrol : MonoBehaviour
{
public float chodz;
public float bieganie;
private float aktual;
public float mouseSens;
public float jumpPlayer;
private Rigidbody rb;
private int jumpLeft = 2;
private bool canJump;
jddsped motor;
void Start()
{
aktual = chodz;
motor = GetComponent<jddsped>();
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.LeftShift))
{
aktual = bieganie;
}
else if (Input.GetKeyUp(KeyCode.LeftShift))
{
aktual = chodz;
}
float _xMove = Input.GetAxisRaw("Horizontal");
float _zMove = Input.GetAxisRaw("Vertical");
Vector3 _moveHorizontal = transform.right * _xMove;
Vector3 _moveVertical = transform.forward * _zMove;
Vector3 _velocity = (_moveHorizontal + _moveVertical).normalized * aktual;
motor.Move(_velocity);
float _yRot = Input.GetAxisRaw("Mouse X");
Vector3 _rotation = new Vector3(0, _yRot, 0) * mouseSens;
motor.Rotate(_rotation);
float _xRot = Input.GetAxisRaw("Mouse Y");
Vector3 _cameraRotation = new Vector3(_xRot, 0, 0) * mouseSens;
motor.RotateCamera(_cameraRotation);
if (Input.GetKeyDown(KeyCode.Space) && jumpLeft > 0)
{
rb.AddForce(Vector3.up * jumpPlayer);
jumpLeft--;
}
}
private void OnCollisionEnter(Collision collision)
{
jumpLeft = 1;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class punkt : MonoBehaviour
{
void OnTriggerEnter(Collider collison)
{
Destroy(gameObject);
}
}