- Home /
Play anim, javascript
I have a javascript that switches cameras and I need it to wait for the camera switch and play an anim first.
var camera1 : Camera;
var camera2 : Camera;
var sound1: AudioClip;
var sound2: AudioClip;
function Start () {
camera1.camera.active = true;
camera2.camera.active = false;
SwitchCameras();
}
function Update () {
//right mouse button
if(Input.GetMouseButtonDown(1)) {
SwitchCameras();
PlayAudio();
}
}
function SwitchCameras(){
if(camera1.camera.active == false){
camera1.camera.active = true;
camera2.camera.active = false;
}
else {
camera1.camera.active = false;
camera2.camera.active = true;
}
}
function PlayAudio(){
if(camera1.camera.active == true){
audio.PlayOneShot(sound1);
}
else if (camera2.camera.active == true){
audio.PlayOneShot(sound2);
}
}
Hi, I see you used the code I wrote as an answer for your previous question, if it worked for you please mark the answer so the question can be solved.
To wait for something the function that will be calling the 'delay' has to be of type IEnumerator and that function has to call a StartCoroutine(YourFunction()) where YourFunction is also of type IEnumerator.
To play an animation use Animation.Play();
Radivarig
Hey sorry, I'm new this site and didn't know I had to mark an answer if it works.
Anyway, the animation script does not seem the work because when I test the game, my Player clips through the terrain and falls into nowhere.
That could be because you don't have a collider:
on your player (click generate collider from mesh in your model inspector)
on the terrain (if by terrain you mean any other object than .terrain file (terrain files have automatic colliders), add a collider component to it, box collider will be enough, note that generating mesh collider is the most processor expensive option)
their colliders are intersecting in edit mode, try pulling the player a bit higher then the terrain before pressing play
Yes I have and my player has a collider, I'm using a terrain and nothing is intersecting. Everything is fine till I press shift to sprint and then I just clip
Answer by abdala · May 23, 2014 at 06:03 AM
if(animation.isplayng("anim name")){camera.active = true} try this in c# :D
Your answer
Follow this Question
Related Questions
Switching cameras (JavaScript) 0 Answers
fps MouseLook with animation applied to camera. 1 Answer
Switching Cameras - Confusion with Two Code Samples 2 Answers
Disabled Camera After Animation Finishes 1 Answer
Camera switch after specific time 1 Answer