background music

Updated on July 1, 2017 in  [R] Scripts
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
4 on June 29, 2017

Unknown identifier: ‘musicPrefab’.

#pragma strict

static var currentScore : int = 0;

var offsetY : float = 40;
var sizeX : float = 100;
var sizeY : float = 40;

function Start () {
currentScore = 0;
if (!GameObject.FindGameObjectWithTag(“MM”)) {
var mManager = Instantiate (musicPrefab, transform.position, Quaternion.identity);
mManager.name = musicPrefab.name;
DontDestroyOnLoad (mManager);
}
}

function OnGUI () {
GUI.Box (new Rect (Screen.width/2-sizeX/2, offsetY, sizeX, sizeY), “Score: ” + currentScore);
}

how do i fix this

  • Liked by
Reply
3 on June 29, 2017

Well, there’s no music prefab assigned. Music prefab just doesn’t exist in this context.

on June 30, 2017

i have a prefab called music

Guru
on June 30, 2017

You having a prefab called music doesn’t instantly make it accessible in code. You’ll have to make a variable and assign that prefab to that variable. 

on July 1, 2017

how do i assign the var to the prefab

 

Show more replies
  • Liked by
Reply
Cancel