在调用另一个脚本中的一个脚本的功能时脚本中的功能无法在编辑器中工作但控制台返回正确的值

时间:2018-05-17 19:04:48

标签: c# unity3d inheritance hololens

附加到CircleMovementTarget GameObject的OrbitFireball脚本中的函数IncreaseRadius从附加到Radius(+)GameObject的editProperties脚本调用时,不返回编辑器或原始脚本中的值的变化,即OrbitFireball(请参阅脚本OribtFireball右侧, OrbitDistance = 0.1)即使控制台返回更改就好了(请参阅控制台,点击半径(+)图标时值会增加。)

使用的Unity版本:2017.2.1f1

App

...

 using HoloToolkit.Unity.InputModule;
 using UnityEngine;
 using System.Collections;

 public class OrbitFireball : MonoBehaviour, IInputClickHandler {

     public Transform target;
     public float orbitDistance = 0.1f;
     public float orbitDegreesPerSec = 90.0f;

     public GameObject Ball;


         // Use this for initialization
     void Start () {

     }

     void Orbit()
     {
         if(target != null)
         {
             // Keep us at orbitDistance from target
             transform.position = target.position + (transform.position - target.position).normalized * orbitDistance;
             transform.RotateAround(target.position, Vector3.back, orbitDegreesPerSec * Time.deltaTime);

             // Ball up and down
             Ball.transform.position = new Vector3(transform.position.x, transform.position.y, target.position.z);

         }
     }

     // Update is called once per frame
     void Update () {

        Orbit(); 
     }


    public void increaseRadius()
    {
        if (orbitDistance <= 0.3f)
        {
            orbitDistance += 0.1f;
            Debug.Log(orbitDistance);
        }
    }

    public void OnInputClicked(InputClickedEventData eventData)
    {
        throw new System.NotImplementedException();
    }
}

...

using System.Collections;
using System.Collections.Generic;
using HoloToolkit.Unity.InputModule;
using UnityEngine;

public class editProperties : OrbitFireball, IInputClickHandler {

    public void OnInputClicked(InputClickedEventData eventData)
    {
        if (gameObject.tag == "RadiusPlus")
        {
            increaseRadius();
        }
    }
}

0 个答案:

没有答案