[Closed] GetComponent different scripts

So I’m making a card game (similar to Hearthstone) and got to the point of making the “attacking” script. Every card has a "CardName"Stats script attached to it with its stats. So I want to access those scripts so I can change the Health value when they “fight”.

    using UnityEngine;
using System.Collections;

public class TestScriptGetter : MonoBehaviour 
{

	public RaycastHit hit = new RaycastHit();
	public Ray ray;
	public float raydistance = 100f;
	
	public string objectname;
	public string scriptname;
	Component script;

	void Update ()
	{
		if (Input.GetMouseButton (0)) 
		{
			ray = Camera.main.ScreenPointToRay (Input.mousePosition);
			if (Physics.Raycast (ray, out hit, raydistance)) 
			{	
				if (hit.transform.tag == "BSBoardCard")
				{
					objectname = hit.transform.gameObject.name;
					scriptname = hit.transform.gameObject.name + "Stats";
					script = GameObject.Find (objectname).GetComponent (scriptname);

					if (GameObject.Find (objectname).GetComponents (scriptname)) {
						GameObject.Find (objectname).GetComponents (scriptname).Health = 2;
					}

//					if (script != null)
//					{
//						script.Health = 2;
//					}

				}
			}
		}
	}



	}

I pretty much understand why it doesn’t work , but is there any way I can fix it ? Different ideas as a whole are accepted as well.

it’s not a burden, nobody is forcing me here.

the Stats script could look something like:

using UnityEngine;

public class Stats : MonoBehaviour
{
    public int Health;
    public int Attack;
    public int Level;
}

if you make that and apply to a game object, you’ll see the 3 variables appear in the inspector; each game object has their own version of these variables.

i’d do things differently, but since you’re new then that should get you started. there’s no point in me using more complex scripts - let’s walk before we run here…

I’m pretty sure you can’t reference Unity scripts jsut by a vague Component type variable. When you want to reference a script, you need to declare it’s explicit type (class).