-2

У меня в коде


   using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PathCreation;

public class moveTram : MonoBehaviour
{
    public PathCreator pathCreator;
    public float speed = 0f;
    public float distanceTravelled;
    public GameObject _camera;
    public AudioSource _audioSource;
    public AudioSource _loopSource;
    public AudioClip vuSFX;
    public AudioClip tramSFX;
    public GameObject VU;
    public int position = 1;
    bool isStarted = false;
    public float acceleration = 1.0f;
    public float maxSpeed = -30;
    public float minSpeed = 20;
    public float brakeStrengh = 5.0f;
    public GameObject LightVolt;


    // Start is called before the first frame update

    
    // Update is called once per frame
    void Update()
    {
        bool IsMouseOverObject(GameObject obj)
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if(Physics.Raycast(ray, out hit))
            {
                Debug.Log("Norm");
                if(hit.collider == obj)
                {
                    Debug.Log("Norm2");
                    return true;
                }
            }
            return false;
        }
        if(Input.GetMouseButtonDown(0) && IsMouseOverObject(VU))
        {
            Debug.Log("Update Normal");
            const int maxPosition = 4;
            _audioSource.PlayOneShot(vuSFX);
            if(position == 1 | position == 2)
            {
                position += 1;
            }
            if(position == maxPosition)
            {
                position = 1;
            }
        }
        switch (position)
        {
            case 1:
                isStarted = false;
                _loopSource.loop = false;
                _loopSource.Stop();
                LightVolt.SetActive(false);
                break;
            case 2:
                isStarted = false;
                _loopSource.loop = false;
                _loopSource.Stop();
                LightVolt.SetActive(false);
                break;
            case 3:
                _loopSource.clip = tramSFX;
                isStarted = true;
                _loopSource.Play();
                _loopSource.loop = true;
                position += 1;
                break;
            case 4:
                LightVolt.SetActive(true);
                break;
        }

        distanceTravelled += speed * Time.deltaTime;
        transform.rotation = pathCreator.path.GetRotationAtDistance(distanceTravelled);
        transform.position = pathCreator.path.GetPointAtDistance(distanceTravelled);
        transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z + 90f);
        Vector3 currentPosition = transform.position;
        currentPosition.y += 2.5f;
        currentPosition.x += 15f;
        transform.position = currentPosition;

        if (Input.GetKey(KeyCode.S))
        {
            speed = Mathf.Lerp(speed, 0.0f, brakeStrengh * Time.deltaTime);
        }

        if (speed < 0.3f && speed > -0.3f && !Input.GetKey(KeyCode.W))
        {
            speed = 0;
        }

        if (isStarted)
        {
            if (Input.GetKey(KeyCode.W))
            {
                speed = Mathf.Lerp(speed, maxSpeed, acceleration * Time.deltaTime);
            }
            else
            {
                speed = Mathf.Lerp(speed, 0.0f, (acceleration - 0.2f) * Time.deltaTime);
            }   
        } 
    }
}


почему то не вызелает Debug,Log("Norm2") в функции IsMouseOverObject. При этом на объекте VU который я указываю в апдейт при первой проверке весит mesh collider с включенными convex trigger. Кто знает почему так происходит?

1
  • Не давайте пожалуйста вопросам бессмысленные заголовки. А то непонятно, как их друг от друга будет отличить. Отредактируйте заголовок и вопрос, добавьте больше деталей, чтобы человек, незнакомый с вашим кодом хотя-бы понял, что этот код делает и зачем.
    – aepot
    20 ноя в 21:22

0

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими условиями использования и подтверждаете, что прочитали и поняли наши политику конфиденциальности и нормы поведения.

Посмотрите другие вопросы с метками или задайте свой вопрос.