animation.Play not working unity not recognising it

first of all, I want to say that I am kind of a newbie here.
I am trying to make some kind of interactive Slideshow presentation for a project,
and i have less than a month to make it (until 27th may)
But to understand how the project will work, I made a sample simpler project where I can learn how the thing works.
It works like this
I have three slides.
I made a transition clip/animation from slide
1 to 2 / 2 to 3 / 3 to 2 / 2 to 1
i made a system that when i click right arrow, the slide page number changes and a transition clip from the slide where i was to the slide where i want to go is played but when writing code in c# to make the animation play
like for example :
animation.Play(“slide1to2clip”);

unity show an error message saying that there is not a definition for “Play”
like in the screenshot below:


thanks in advance

Code in C#:--------------------------------------------------------------------------------------------------------------------------------

using UnityEngine;
using System.Collections;

public class Motordepagina : MonoBehaviour {

public int pagina = 1;

void Start ()
{

pagina = 1;

}

void Update ()
{

if (Input.GetKeyDown (KeyCode.RightArrow))
{
pagina = pagina + 1;
Pafrente ();
}

if (Input.GetKeyDown (KeyCode.LeftArrow))
{
pagina = pagina - 1;
Patraz ();
}

if (pagina < 0)
{
print (“negativa”);
pagina = 1;
}

}

void Pafrente()
{

if (pagina == 1)
{
//naoacontece nada
}

if (pagina == 2)
{
Debug.Log (“pagina-2 vinda da1”);

animation.Play (“slide1to2clip”);
}

if (pagina == 3)
{
//starts the animation clip2-3
}
}

void Patraz()
{

if (pagina == 1)
{
//starts the animation clip2-1
}

if (pagina == 2)
{
Debug.Log (“pagina-2vindadatres”);
//starts the animation clip3-2
}

if (pagina == 3)
{
//starts the animation clip4-3
}
}

}

sorry, i already found the problem and managed to solve it

1 Like

For the record the problem is that you are using the deprecated shortcut property. Replace animation with GetComponent() and it should work fine.

It’s also worth noting that PowerPoint is superior to Unity for making slide shows. :wink:

1 Like