value to a variable

might be a little funny, but how do I store the string value from a into a string-type var?


string _name = // throws an error, because I cannot establish a link to tweak the name variable, and I don’t want to - I only need the value xD

A field initializer cannot reference the nonstatic field, method, or property `UnityEngine.Component.transform’

Sorry if this is too simple :smiley:

Here is the code:

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

public class NodeSpark : MonoBehaviour {

	string string_name =; //throws the previously described exception
}//end of class

You can only do that inside of a function, so you could do that in the Start or Awake functions.

Don’t try to run code outside functions. Only declare variables outside functions; use Start or Awake to run initialization code.

// Declare variable only; run code that assigns a value in a function
string string_name;