- Home /
What is wrong with this script?
this is a script for fading flashlight. the engine keeps saying "light is not a member of 'System.Type'"? what is wrong? plus, "No appropriate version of 'UnityEngine.AudioSource.PlayOneShot' for the argument list '(System.Type)' was found"? i don't think there is any "javascript grammar" error, but these error message keeps popping out. what happened? and how do i fix it? some help would be appreciated.
var onClick = AudioClip;
var lightSource = Light;
function Start ()
{
lightSource.light.enable = false;
lightSource.light.intensity = 2.85;
}
function Update()
{
if(lightSource.light.enable == true)
{
lightSource.light.intensity -= 0.1 * Time.deltaTime / 5;
Debug.Log(lightSource.light.intensity);
}
if(Input.GetKeyDown("f"))
{
audio.PlayOneShot(onClick);
if(lightSource.light.enabled == false)
{
lightSource.light.enable == true;
}
else
{
lightSource.light.enabled = false;
}
}
}
Answer by Rodrigo Cordova · Oct 12, 2014 at 02:56 AM
Hey bro, i have a FlashLight script if you want, i don't know if it's exactly what you want, but this is what i have :
#pragma strict
var SoundFX : AudioClip;
function Start () {
light.enabled = true;
}
function Update() {
if (Input.GetKeyDown("f")) {
audio.clip = SoundFX;
audio.Play();
if (light.enabled == true)
light.enabled = false;
else
light.enabled = true;
}
}
Answer by Kiwasi · Oct 12, 2014 at 02:38 AM
This is a classic JavaScript typing error. Two options to avoid this error
Use C#
Add #pragma strict to the top of your code
To fix your instance you simply need to type your variables
var onClick : AudioSource;
// and so on...
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
If statement only work once? 1 Answer
Where to learn free unity scripting 2 Answers