Destorying and respawning objects with raycasting

This code worked as-is just a little while ago. I’m trying to figure out what I did wrong. Did I remove something important without knowing it?

I’m sure it’s something obvious in the syntax. It errors saying there is something wrong with line 25, which I know there isn’t.

On a side note I am having trouble getting destroy working right
Also when the ray hits tag “wall”, I want to Instantiate the object I just destroyed.
Tried prefabs, but had some issues with, destroying them.

using UnityEngine;
using System.Collections;

public class RayCast : MonoBehaviour 
	//cast ray
	public GameObject Character;
	private RaycastHit rayHit;
	private GameObject ray;
	//destroy wall
//	public GameObject Wall;
	// Use this for initialization
	void Start () 
	// Update is called once per frame
	void Update () 
		Vector3 myTransform = ray.transform.forward;
		if(Physics.Raycast(transform.position, myTransform, out rayHit, 10))
//				Debug.DrawRay(transform.position, Character.transform.forward,;
				print("Destroy Wall!");
//			Destroy(Wall, 0);
				print("Hit a Wall!");
//		if(rayHit.collider.gameObject.tag == "wall")
//			Instantiate(/*Resources.Load(redWall));

you haven’t initialised ray

ray = new GameObject();

might help

When posting errors like this one, it is very helpful if you past the error copied directly from the Console window. There are no syntax errors in this code. But you are not initializing ‘ray’ That is you declare it on like 10, but it is never “hooked up” to any game object. So on line 25, you get an error at runtime. I’m not sure what is going specifically with your Destroy(), but you test for the tag “red” on line 29 but your commented out code destorys “wall”. Typically you would want to destroy what your Raycast() hits:


As for the prefab and destroy issue, if you really have a true prefab, then I suspect you tried to destroy the prefab and not the scene object.