using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ScalingAndRotating : UnityEngine.MonoBehaviour
{
//Camera
public Camera playerCamera;
//Scaling
public bool canScale = false;
private Scaling scaling;
//Lights
public DimLights dimlights;
private Coroutine lightCoroutine;
//Colors
private Colors colors;
//Rotating
public bool stopRotation = false;
private Rotating rotating;
private void Start()
{
scaling = GetComponent<Scaling>();
scaling.Inits();
colors = GetComponent<Colors>();
colors.Start();
rotating = GetComponent<Rotating>();
}
// Use this for initialization
void Update()
{
if (playerCamera != null)
{
//Scaling
if (canScale == true)
{
if (Input.GetKeyDown(KeyCode.G) && canScale == true)
{
Scaling();
}
}
}
//Rotate
if (Input.GetKey(KeyCode.R) && !scaling.scaleUp)
{
rotating.x += Time.deltaTime * rotating.rotationSpeed;
scaling.objectToScale.transform.localRotation = Quaternion.Euler(0, 0, rotating.x);
rotating.keyPressed = true;
}
if (Input.GetKeyUp(KeyCode.R))
{
rotating.keyPressed = false;
}
if (!rotating.keyPressed && !scaling.scaleUp && rotating.rotateBack == false)
{
scaling.objectToScale.transform.rotation = Quaternion.LookRotation(playerCamera.transform.forward);
}
if (!scaling.scaleUp && stopRotation == false)
{
//rotating.x += Time.deltaTime * rotating.rotationSpeed;
//scaling.objectToScale.transform.localRotation = Quaternion.Euler(0, 0, rotating.x);
}
}
public void Scaling()
{
//Flip the scale direction when F key is pressed
scaling.scaleUp = !scaling.scaleUp;
//Stop old coroutine
if (scaling.scaleCoroutine != null)
StopCoroutine(scaling.scaleCoroutine);
if (lightCoroutine != null)
StopCoroutine(lightCoroutine);
//Scale up
if (scaling.scaleUp)
{
//Start new coroutine and scale up within 5 seconds and return the coroutine reference
rotating.rotateBack = false;
scaling.scaleCoroutine = StartCoroutine(scaling.scaleOverTime(scaling.objectToScale, scaling.maxSize, scaling.duration, playerCamera));
if (dimlights.lightsOnOff == false)
lightCoroutine = StartCoroutine(dimlights.dimLightOverTime(1, scaling.duration));
}
//Scale Down
else
{
//Start new coroutine and scale up within 5 seconds and return the coroutine reference
rotating.rotateBack = true;
scaling.scaleCoroutine = StartCoroutine(scaling.scaleOverTime(scaling.objectToScale, scaling.minSize, scaling.duration, playerCamera));
if (dimlights.lightsOnOff == false)
lightCoroutine = StartCoroutine(dimlights.dimLightOverTime(0, scaling.duration)); ;
}
}
}
Используя точку останова в начале строки в строке:
colors = GetComponent<Colors>();
Я вижу, что масштабирование не равно нулю.
Но затем игра запускается и начинает несколько раз в строке внутри Scaling:
scaling.scaleUp = !scaling.scaleUp;
И здесь масштабирование равно нулю.
Я вызываю метод Scaling из этого скрипта:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class NaviConversations : MonoBehaviour
{
public ConversationTrigger conversationTrigger;
public ScalingAndRotating scalingandrotating;
public void NaviConversationTrigger()
{
// Scale up and rotate navi here
scalingandrotating.Scaling();
}
private void Update()
{
if (conversationTrigger.conversationEnd == true &&
conversationTrigger.NaviConversationInProgress == true)
{
// Scale down and rotate navi here
scalingandrotating.Scaling();
conversationTrigger.conversationEnd = false;
conversationTrigger.NaviConversationInProgress = false;
}
}
}
Если масштабирование не было нулевым в начале, почему, когда скрипт NaviConversations вызывает масштабирование
scalingandrotating.Scaling();
Теперь масштабирование равно нулю?