Problems with highlighter script

Good morning all,

I hope everyone has reason to be excited for the weekend.
I will be trying to get this new highlighter script to work. The purpose of the script is to cause an object that is hit by a raycast generated from my player ( or his camera, rather ) to become highlighted by giving it a new shader. I have the shader and it works, okay, but I seem to be having a multitude of problems with the script. Not very familiar with C# , but I got a tutorial that uses it and a business acquaintance who swears by it. So, I was wondering if anyone would be willing to help out with this. I’m going to post what I have and the errors I am receiving and perhaps someone could find it in their heart to point out where I’m screwing up. Thank you for your time this morning.

so here’s the script so far…

using UnityEngine;
using System.Collections;

public class PlayerInteractionScript : MonoBehaviour {

private Transform myCam;
private GameObject viewing;
private Shader holdShader;

public float rayCastDistance = 3.0f;
public Shader highlightShader;

// Use this for initialization
void Start () {
myCam = GetComponentInChildren().transform;
Screen.lockCursor = true;
}

// Update is called once per frame
void Update () {
if (viewing != null) {
if (viewing.tag == “HotSpot”) {
//unhighlight hotspot
}
}
viewing = LookingAt();
if (viewing != null) {
//highlight hotspot
}
}
}

GameObject LookingAt () {
Ray ray = new Ray(myCam.position, myCam.forward);
RaycastHit hit = new RaycastHit();
if (Physics.Raycast (ray, out hit, rayCastDistance)) {
return hit.transform.gameObject;
} else {
return null;
}
}
}

and here are the errors I am getting

“Assets/Highlighter.cs(43,1): error CS8025: Parsing error”
“Assets/Highlighter.cs(34,12): error CS0116: A namespace can only contain types and namespace declarations”

I have highlighted in RED the lines involving the errors. Hope that helps.

Thanks
-Richard

One too many closing brackets in the Update function.

The bracket “}” you have just above the red highlighted text GameObject LookingAt () needs to be removed.

You have to many }s at the end of your Update method. Your ending the class with the last one.

Well thank you very much, gentlemen. That fixed that issue but it appears I have a new set of errors. I’m putting both of the “finished” scripts down now. If you find the time I would again appreciate your help. This is a learning process for me right now and I am grateful for your generosity with your time and knowledge.

“PlayerInteractionScript.cs”

using UnityEngine;
using System.Collections;

public class PlayerInteractionScript : MonoBehaviour {

private Transform myCam;
private GameObject viewing;
private Shader heldShader;

public float rayCastDistance = 3.0f;
public Shader highlightShader;

// Use this for initialization
void Start () {
myCam = GetComponentInChildren().transform;
Screen.lockCursor = true;
}

// Update is called once per frame
void Update () {
if (viewing != null) {
if (viewing.tag == “HotSpot”) {
//unhighlight hotspot
InterActiveHotspotScript hs = viewing<GetComponent.InterActiveHotspotScript>();
hs.SwitchShader(heldShader);
}
}
viewing = LookingAt();
if (viewing != null) {
//highlight hotspot
InterActiveHotspotScript hs = viewing<GetComponent.InterActiveHotspotScript>();
heldShader = hs.SwitchShader(highlightShader);

}
}

GameObject LookingAt () {
Ray ray = new Ray(myCam.position, myCam.forward);
RaycastHit hit = new RaycastHit();
if (Physics.Raycast (ray, out hit, rayCastDistance)) {
return hit.transform.gameObject;
} else {
return null;
}
}
}

“InterActiveHotspotScript.cs”

using UnityEngine;
using System.Collections;

public class InterActiveHotspotScript : MonoBehaviour {

public Shader SwitchShader (Shader newShader) {
Shader previousShader = renderer.material.shader;
renderer.material.shader = newShader;
return previousShader;
}
}

errors:
"Assets/HOTSPOTSCRIPTS/PlayerInteractionScript.cs(32,63): error CS0246: The type or namespace name `GetComponent’ could not be found. Are you missing a using directive or an assembly reference?

Also, for future reference, is there a way I can imbed or insert the scripts in my post so it doesn’t take up so much space?

Each of those should read:

InterActiveHotspotScript hs = viewing.GetComponent();

Reference is nice:

Oh, big mister b. I believe I may owe some beers already.

Thanks, sir