【问题标题】:Change image with button next/previous in a Scroll View in Unity3d在 Unity3d 的滚动视图中使用按钮更改图像下一个/上一个
【发布时间】:2016-01-18 13:20:31
【问题描述】:

如何使用 C# 在 Unity3D 中动态加载图像时使用按钮更改下一个图像。

 public void NextPictureInGallery()
    { 
        int i=0;//index of image
        if(i + 1 < image.Length)
        {
            i++;
        }
     }

图像在滚动视图中

【问题讨论】:

  • 显示一些你尝试过的代码
  • @RasaMohamed 我放了几行和一张图片来描述我想做的事情

标签: c# unity3d


【解决方案1】:

您可以更改 ScrollRect 的 normalized position

【讨论】:

    【解决方案2】:
    public Sprite[] myImage; // Its length descried in Inspector and assign sprite images
    public Button myBtn;
    int i=0;
    void Update()
    {
      if(Input.GetMouseButtonDown(0)) // HeresI'm checking condition for Mouse Input,  Change this based on your 
      {    
        if(i+1 < myImage.Length)
        {
         //Make sure it is added in the Inspector.
         myBtn.image.sprite = myImage[i];
         i++;
        }
      }
    }
    

    Reference

    检查并告诉我

    【讨论】:

    • 不工作,但我不想改变下一个按钮的图片,我想改变图像,就像在滚动视图中用鼠标拖动一样,增加一个当前图像。
    • 你的意思是把图片从一个按钮拖到另一个按钮...!
    • 当点击中心屏幕上的按钮时,我想看到图片中的图像 3。
    • 你能把你的代码显示在这里,直到现在你尝试了什么,以便我可以轻松地帮助你
    猜你喜欢
    • 2020-09-21
    • 1970-01-01
    • 2013-12-12
    • 2019-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-11
    • 1970-01-01
    相关资源
    最近更新 更多