using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
public class PlayerController : MonoBehaviour
{
[Header("General")]
[Tooltip("In ms^-1")] [SerializeField] float controlSpeed = 24f;
[Tooltip("In m")] [SerializeField] float xRange = 6f;
[Tooltip("In m")] [SerializeField] float yRange = 4f;
[SerializeField] GameObject[] guns;
[Header("Screen-position Based")]
[SerializeField] float positionPitchFactor = -5f;
[SerializeField] float positionYawFactor = 5f;
[Header("Control-throw Based")]
[SerializeField] float controlPitchFactor = -20f;
[SerializeField] float controlRollFactor = -20f;
float xThrow, yThrow;
bool isControlEnabled = true;
private bool landed = true;
private bool fired = true;
private GameController gameController;
private void Start()
{
gameController = FindObjectOfType<GameController>();
}
// Update is called once per frame
void Update()
{
if (isControlEnabled)
{
ProcessTranslation();
ProcessRotation();
ProcessFiring();
}
}
void OnPlayerDeath()
{
isControlEnabled = false;
gameController.GameOver();
}
private void ProcessRotation()
{
float pitchDueToPosition = transform.localPosition.y * positionPitchFactor;
float pitchDueToControlThrow = yThrow * controlPitchFactor;
float pitch = pitchDueToPosition + pitchDueToControlThrow;
float yaw = transform.localPosition.x * positionYawFactor;
float roll = xThrow * controlRollFactor;
transform.localRotation = Quaternion.Euler(pitch, yaw, roll);
}
private void ProcessTranslation()
{
xThrow = CrossPlatformInputManager.GetAxis("Horizontal");
yThrow = CrossPlatformInputManager.GetAxis("Vertical");
float xOffset = xThrow * controlSpeed * Time.deltaTime;
float yOffset = yThrow * controlSpeed * Time.deltaTime;
float rawXPos = transform.localPosition.x + xOffset;
float clampedXPos = Mathf.Clamp(rawXPos, -xRange, xRange);
float rawYPos = transform.localPosition.y + yOffset;
float clampedYPos = Mathf.Clamp(rawYPos, -yRange, yRange);
transform.localPosition = new Vector3(clampedXPos, clampedYPos, transform.localPosition.z);
}
void ProcessFiring()
{
if (CrossPlatformInputManager.GetButton("Fire"))
{
SetGunsActive(true);
}
else
{
SetGunsActive(false);
}
}
private void SetGunsActive(bool isActive)
{
foreach (GameObject gun in guns) // care may affect death FX
{
var emissionModule = gun.GetComponent<ParticleSystem>().emission;
emissionModule.enabled = isActive;
}
}
void FireGunsOn()
{
isControlEnabled = false;
if (!fired)
{
gameController.GameOver();
}
}
void FireGunsOff()
{
isControlEnabled = true;
fired = false;
}
}
void OnPlayerLanding()
{
isControlEnabled = false;
if (!landed)
{
gameController.GameOver();
}
}
void OnPlayerTakeOff()
{
isControlEnabled = true;
landed = false;
}
Я пытаюсь автоматически запустить оружие при запуске.когда я начинаю игру, лазерные пушки начинают стрелять, не нажимая огонь / пробел.Я добавил void fireGunsOn и fireGunsOff методы, но я получаю синтаксическую ошибку для void OnPlayerLanding (), утверждающую это: Assets / Scripts / PlayerController.cs (120,0): ошибка CS1525: неожиданный символ `void 'Любое понимание приветствуется?