chenxin
2020-10-27 49f88e6493466a1723dd6b3967ff4c70f723db5d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
 
namespace MagicArsenal
{
 
public class MagicButtonScript : MonoBehaviour
{
    public GameObject Button;
    Text MyButtonText;
    string projectileParticleName;        // The variable to update the text component of the button
 
    MagicFireProjectile effectScript;        // A variable used to access the list of projectiles
    MagicProjectileScript projectileScript;
 
    public float buttonsX;
    public float buttonsY;
    public float buttonsSizeX;
    public float buttonsSizeY;
    public float buttonsDistance;
    
    void Start ()
    {
        effectScript = GameObject.Find("MagicFireProjectile").GetComponent<MagicFireProjectile>();
        getProjectileNames();
        MyButtonText = Button.transform.Find("Text").GetComponent<Text>();
        MyButtonText.text = projectileParticleName;
    }
 
    void Update ()
    {
        MyButtonText.text = projectileParticleName;
//        print(projectileParticleName);
    }
 
    public void getProjectileNames()            // Find and diplay the name of the currently selected projectile
    {
        // Access the currently selected projectile's 'ProjectileScript'
        projectileScript = effectScript.projectiles[effectScript.currentProjectile].GetComponent<MagicProjectileScript>();
        projectileParticleName = projectileScript.projectileParticle.name;    // Assign the name of the currently selected projectile to projectileParticleName
    }
 
    public bool overButton()        // This function will return either true or false
    {
        Rect button1 = new Rect(buttonsX, buttonsY, buttonsSizeX, buttonsSizeY);
        Rect button2 = new Rect(buttonsX + buttonsDistance, buttonsY, buttonsSizeX, buttonsSizeY);
        
        if(button1.Contains(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)) ||
           button2.Contains(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)))
        {
            return true;
        }
        else
            return false;
    }
}
}