Get variables from other scripts C#

Hi! I try to search how to get varibles form other scripts in C#
but I found the way in JAVA…

in Unity - Scripting API: GameObject.GetComponent
it not have example code in C#
Can You Please Give Examples

this is my CameraControl.cs I want to get target form this script to Actor.cs

using UnityEngine;
using System.Collections;


public class CameraControl : MonoBehaviour {
	
	RaycastHit hit;
	bool leftClickFlag = true;
	public GameObject actor;
	public string floorTag;

	public Vector3 target;

	Actor actorScript;
	
	void Start()
	{
		if (actor != null)
		{
			actorScript = (Actor)actor.GetComponent(typeof(Actor));
		}
	}
	
	void Update () 
	{
		/***Left Click****/
		if (Input.GetKey(KeyCode.Mouse0) && leftClickFlag)
			leftClickFlag = false;
		
		if (!Input.GetKey(KeyCode.Mouse0) && !leftClickFlag)
		{   
			leftClickFlag = true;
			Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);


			if (Physics.Raycast(ray, out hit, 1500))
			{   
				if (hit.transform.tag == floorTag)
				{   
					float X = hit.point.x;
					float Y = hit.point.y;
					target = new Vector3(X, Y, actor.transform.position.z);
					actorScript.MoveOrder(target);
					print("NewTarget is"+target);

				}
			}
		}
	}
}

this is my Actor.cs

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Actor : MonoBehaviour {

	
	private void SetTarget()
	{      // I want to get target form CameraControl.cs to here
		path = control.Path(transform.position, m_target);
		nodeIndex = 0;
		onNode = true;
	}
	
	
}

Please tell me how to do it
Thanks!

You will need to change the line “private void SetTarget()” in your Actor.cs to be:

public void SetTarget()

then you can call it with

actorScript.SetTarget();

in your CameraControl.cs file.

Also, change the line “actorScript = (Actor)actor.GetComponent(typeof(Actor));” to be:

actorScript = actor.GetComponent<Actor>();