How to return a Vector3 value?

Hey guys, so I’m trying to figure out how the return of the void works.

I’m trying to get a vector3 from a function;

So I have, Vector3 target in one script, an wish to assign it to the result of this long function (in another script); What I am tryin to get is the return hit.point; at the end of the function

I was trying something like:

				target = this.GetComponent<AimingSystem> ().AimForHomming ();

But it dosen’t work :frowning:

Any help much apreciated, thanks for your time

	public void AimForHomming()
		aimingforHomming = true;

		y2 += Input.GetAxis ("Mouse Y") * screenSens;
		if (y2 >= sH) {
			y2 = sH;
		if (y2 <= 0) {
			y2 = 0;

		x2 += Input.GetAxis ("Mouse X") * screenSens;
		if (x2 >= sW) {
			x2 = sW;
		if (x2 <= 0) {
			x2 = 0;

		Vector3 screenPoint = new Vector3 (x2, y2 , 2);
		Vector3 WorldPos = this.GetComponent<Attributes> ().myCam.ScreenToWorldPoint (screenPoint);
		aimObj.SetActive (true);
		aimObj.transform.position = WorldPos;

		Ray ray = new Ray (this.GetComponent<Attributes> ().myCam.transform.position,( aimObj.transform.position - this.GetComponent<Attributes> ().myCam.transform.position));
		RaycastHit hit;
		if (Physics.Raycast (ray, out hit, 1000, ~2)) {
			if (hit.transform != this.GetComponent<Attributes> ().myBall) {
				return hit.point;

Change your function declaration to

public Vector3 AimForHomming() { …

The use of void means that the function doesn’t return anything, if you want to return something your need to replace void with the type that you want to return.

Read the part about return type at the end.
C# Methods

Methods can return a value to the caller. If the return type, the type listed before the method name, is not void, the method can return the value by using the return keyword. A statement with the return keyword followed by a value that matches the return type will return that value to the method caller.