GitHtub / Hearthstone

51 stars 43 forks source link

Update scripts to latest version of Unity #1

Open DealPete opened 6 years ago

DealPete commented 6 years ago

I can't run this because the scripts use deprecated APIs

FatPugStudio commented 6 years ago

Install older Unity version.

droidinteractive commented 6 years ago

This was pushed 3 years ago. Naturally the scripts won't be up-to-date. If you need help converting to the new Unity version I will be happy to help. If you are not already, I suggest using Visual Studio as Intellisense will greatly assist in fixing any deprecated function calls.

droidinteractive commented 6 years ago
  1. Delete iTween folder from project
  2. Download latests version from Unity Asset Store and install package
  3. Delete NGUI folder from project
  4. Download latest version from Unity Asset Store and install package
  5. Replace UIctrl.cs with the following:
    
    using UnityEngine;
    using System.Collections;

public class UIctrl : MonoBehaviour { Resolution nowResolution;

public UIPopupList ResolutionPoplist;
public GameObject setting;
public UIToggle fullscreen;

int count;
void showSetting()
 {
     count = 0;
     setting.SetActive(!setting.activeSelf);
    if (setting.activeSelf)
    {
        getResolution();
        getFullScreen();
        getQuality();
    }
 }
void getResolution()
{
    nowResolution = Screen.currentResolution;
    ResolutionPoplist.items.Clear();
    foreach (Resolution res in Screen.resolutions)
    {
        ResolutionPoplist.items.Add(res.width + "*" + res.height);
    }
    ResolutionPoplist.value = nowResolution.width + "*" + nowResolution.height;
}
void getFullScreen()
{
    fullscreen.isChecked = Screen.fullScreen;
}
void setFullScreen()
{
    Screen.fullScreen = fullscreen.isChecked;
}
QualityLevel nowQuality;
public UIPopupList QualityPoplist;
void getQuality()
{
    nowQuality = (QualityLevel)QualitySettings.GetQualityLevel();
    QualityPoplist.items.Clear();
    for (int x = 0; x < 6;x++ )
    {
        QualityLevel q = (QualityLevel)x;
        QualityPoplist.items.Add(q.ToString());
    }
    QualityPoplist.value = nowQuality.ToString();
}
void setQuality()
{
    int cur=QualityPoplist.items.IndexOf(QualityPoplist.value);

    QualitySettings.SetQualityLevel(cur);
}
void setResolution()//开始会被调用2次
{
if (count<2)//用来解决分辨一打开就会被调用
{
    count++;
    return;
}
    Debug.Log("出现");
    string[] sz = ResolutionPoplist.value.Split('*');
    Screen.SetResolution(int.Parse(sz[0]), int.Parse(sz[1]), fullscreen.isChecked);

}
void exitGame()
{
    Application.Quit();
}

}

6. Now its time to fix all of the Unity deprecated function calls. Visual Studio will tell you what is wrong and what to use, a little tedious, but you can fix the remaining issues in about 10-20 minutes.

Example:

void push() { animation["boxcampush"].speed = 1; animation.Play("boxcampush"); box.animation["boxopendoor"].speed = 1; box.animation.Play("boxopendoor");

}
This is going to throw errors on the animation portion due to the following UnityUpgradeable error:

CS0619 'Component.animation' is obsolete: 'Property animation has been deprecated. Use GetComponent() instead. (UnityUpgradable)'


The corrected code would look something like this:

void push() { GetComponent()["boxcampush"].speed = 1; GetComponent().Play("boxcampush"); box.GetComponent()["boxopendoor"].speed = 1; box.GetComponent().Play("boxopendoor"); }

The more efficient way would be to declare a private Animation variable so you only have to call the GetComponent function once, for example:

private Animation myAnimation;

Then define it in the Start function:

myAnimation = GetComponent();


Then use the myAnimation variable.

Hope this helps you out.