方法必须具有返回类型(Unity 3D)

时间:2019-04-02 06:07:45

标签: c# unity3d

我正在尝试使播放器的前进速度恒定,并且在编译时出现此错误。

public class Speed
{
    public static int movespeed = 1;
    public Vector3 userDirection = Vector3.right;
    public Start()
    {

    }

    public void Update()
    {
        transform.Translate(userDirection * movespeed * Time.deltaTime); 
    }
}

2 个答案:

答案 0 :(得分:2)

您忘记了Start方法的返回类型:

公共无效开始()

通过这种方式,您还忘记了对MonoBehavior的继承(如果要将脚本附加到游戏对象上);-)

公共课速度:单举行为

    jQuery(function(){
    var owl1 = jQuery('#owl-carousel1');
    var owl2 = jQuery('#owl-carousel2');
    owl1.owlCarousel({
        autoplay: 2000,
        items:1,
        nav:false,
        autoplay:true,
        autoplayTimeout:5000,
        autoplayHoverPause:true, 
        loop: true,
        dots: false,
        onInitialized  : counter, //When the plugin has initialized.
        onTranslated : counter //When the translation of the stage has finished.
    });

owl2.owlCarousel({
        autoplay: 2000,
        items:1,
        nav:false,
        autoplay:true,
        autoplayTimeout:5000,
        autoplayHoverPause:true, 
        loop: true,
        dots: false,
        onInitialized  : counter, //When the plugin has initialized.
        onTranslated : counter //When the translation of the stage has finished.
    });
    jQuery('.customNextBtn').click(function() {
        owl1.trigger('next.owl.carousel');
    })
    // Go to the previous item
    jQuery('.customPrevBtn').click(function() {
        // With optional speed parameter
        // Parameters has to be in square bracket '[]'
        owl1.trigger('prev.owl.carousel', [300]);
    })
    function counter(event) {
       var element   = event.target;         // DOM element, in this example .owl-carousel
        var items     = event.item.count;     // Number of items
        var item      = event.item.index + 1;     // Position of the current item

      // it loop is true then reset counter from 1
      if(item > items) {
        item = item - items
      }
      jQuery(element).parent().find('.counter').html(item + " / " + items);
    }
    });

答案 1 :(得分:1)

您的start方法没有返回类型。改为分配一个。

public void Start()
{
}

通过这种方式,这实际上是最基本的,不应该属于这里。