hi there, im converting a script from C# to javascript.
the problem here is there is an error stated :
BCE0020 : An instance of type 'UnityEngine.Component is required to access non static member ‘GetComponent’.
any help is appreciated… ^___^
here are the scripts.
JAVASCRIPT
#pragma strict
var camera : GameObject;
var menu : GameObject;
var SelectSound : AudioClip;
var SelectDownSound : AudioClip;
function Start(){
camera = GameObject.Find("Main Camera");
menu = GameObject.Find("Menu");
}
function OnMouseEnter(){
audio.clip = SelectSound;
audio.Play();
}
function OnMouseOver(){
renderer.material.color = Color.blue;
}
function OnMouseExit(){
renderer.material.color = Color.white;
}
function OnMouseDown(){
audio.clip = SelectDownSound;
audio.Play();
RotateCamera();
}
function RotateCamera(){
Camera.GetComponent(SmoothLookAtJS).target = menu.transform;// error in JS
}
C# SCRIPT
using UnityEngine;
using System.Collections;
public class BackToMenu : MonoBehaviour
{
public GameObject camera;
public GameObject menu;
public AudioClip SelectSound;
public AudioClip SelectDownSound;
void Start()
{
camera = GameObject.Find("Main Camera");
menu = GameObject.Find("Menu");
}
void OnMouseEnter()
{
audio.clip = SelectSound;
audio.Play();
}
void OnMouseOver()
{
renderer.material.color = Color.blue;
}
void OnMouseExit()
{
renderer.material.color = Color.white;
}
void OnMouseDown()
{
audio.clip = SelectDownSound;
audio.Play();
RotateCamera();
}
void RotateCamera()
{
camera.GetComponent<SmoothLookAt>().target = menu.transform;// no error on C#
}
}