I am really new to scripting. This post relates to my other post here. Can anyone explain how the keyframe works in scripting. I am trying to get an object to move through (x,y) space and have the following script. It is not working. I really do not want to set all these keyframes in the animation editor but right now that seems to be the only solution.
This script returns the error: Cannot convert ‘float’ to ‘UnityEngine.Keyframe’
I am not sure what I am doing wrong.
private var animX : AnimationCurve;
private var animY : AnimationCurve;
private var xs : Keyframe[];
private var ys : Keyframe[];
function Start(){
xs = new Keyframe [86];
xs[0]=316;
xs[1]=309;
xs[2]=307.195;
xs[3]=304.578;
xs[4]=302.984;
xs[5]=300.305;
xs[6]=298.711;
xs[7]=296.418;
xs[8]=293.93;
xs[9]=292.051;
xs[10]=289.359;
xs[11]=287.797;
xs[12]=285.07;
xs[13]=283.367;
xs[14]=280.891;
xs[15]=278.531;
xs[16]=276.293;
xs[17]=273.594;
xs[18]=271.855;
xs[19]=269.453;
xs[20]=267.195;
xs[21]=264.656;
xs[22]=262.27;
xs[23]=260.5;
xs[24]=257.707;
xs[25]=255.406;
xs[26]=253.273;
xs[27]=251.34;
xs[28]=248.391;
xs[29]=246.5;
xs[30]=242.691;
xs[31]=240.594;
xs[32]=237.656;
xs[33]=235.594;
xs[34]=233.156;
xs[35]=230.156;
xs[36]=227.949;
xs[37]=225.465;
xs[38]=222.57;
xs[39]=220.43;
xs[40]=217.91;
xs[41]=214.852;
xs[42]=212.734;
xs[43]=210.094;
xs[44]=206.871;
xs[45]=204.781;
xs[46]=201.914;
xs[47]=198.926;
xs[48]=196.309;
xs[49]=193.82;
xs[50]=190.891;
xs[51]=188.145;
xs[52]=180.074;
xs[53]=177.273;
xs[54]=176.312;
xs[55]=173.105;
xs[56]=166;
xs[57]=162.832;
xs[58]=161.762;
xs[59]=158.117;
xs[60]=155.5;
xs[61]=152.504;
xs[62]=148.926;
xs[63]=146.242;
xs[64]=143.07;
xs[65]=139.938;
xs[66]=132.969;
xs[67]=130.141;
xs[68]=126.211;
xs[69]=123.418;
xs[70]=120.168;
xs[71]=116.238;
xs[72]=113.176;
xs[73]=109.391;
xs[74]=106.176;
xs[75]=102.43;
xs[76]=98.2344;
xs[77]=95.0703;
xs[78]=91.6484;
xs[79]=86.9258;
xs[80]=76.9258;
xs[81]=71.4258;
xs[82]=65.9258;
xs[83]=61.5;
xs[84]=53;
xs[85]=46;
xs[86]=41.1055;
ys = new Keyframe [86];
ys[0]=37;
ys[1]=-23;
ys[2]=-28.8281;
ys[3]=-37.4141;
ys[4]=-42.6523;
ys[5]=-51.0625;
ys[6]=-56.3242;
ys[7]=-63.7891;
ys[8]=-71.0977;
ys[9]=-77.5312;
ys[10]=-85.7539;
ys[11]=-90.7969;
ys[12]=-99.625;
ys[13]=-105.09;
ys[14]=-112.609;
ys[15]=-120.238;
ys[16]=-127.316;
ys[17]=-135.5;
ys[18]=-140.777;
ys[19]=-148.637;
ys[20]=-156.262;
ys[21]=-163.203;
ys[22]=-171.703;
ys[23]=-177.293;
ys[24]=-185.223;
ys[25]=-193.66;
ys[26]=-200.383;
ys[27]=-206.645;
ys[28]=-215.742;
ys[29]=-221.676;
ys[30]=-232.5;
ys[31]=-239.449;
ys[32]=-248.328;
ys[33]=-255.07;
ys[34]=-262.738;
ys[35]=-272.184;
ys[36]=-279.195;
ys[37]=-286.992;
ys[38]=-296.613;
ys[39]=-303.348;
ys[40]=-311.414;
ys[41]=-321.285;
ys[42]=-328.336;
ys[43]=-336.746;
ys[44]=-347.133;
ys[45]=-354.199;
ys[46]=-363.125;
ys[47]=-373.195;
ys[48]=-381.16;
ys[49]=-390.211;
ys[50]=-399.695;
ys[51]=-408.82;
ys[52]=-432.449;
ys[53]=-444.145;
ys[54]=-447.109;
ys[55]=-458.871;
ys[56]=-482.305;
ys[57]=-494.809;
ys[58]=-498.281;
ys[59]=-510.703;
ys[60]=-519.906;
ys[61]=-529.945;
ys[62]=-542.645;
ys[63]=-551.871;
ys[64]=-563.031;
ys[65]=-574.172;
ys[66]=-598.582;
ys[67]=-608.387;
ys[68]=-622.523;
ys[69]=-632.309;
ys[70]=-644.449;
ys[71]=-658.461;
ys[72]=-669.395;
ys[73]=-682.445;
ys[74]=-695.039;
ys[75]=-708.309;
ys[76]=-724.16;
ys[77]=-736.371;
ys[78]=-747;
ys[79]=-757.039;
ys[80]=-775.039;
ys[81]=-785.539;
ys[82]=-797.039;
ys[83]=-806;
ys[84]=-820;
ys[85]=-833;
ys[86]=-845.566;
for(var i = 0; i < 86 ; i++)
xs[i] = Keyframe;
for(var j = 0; j < 86 ; i++)
ys[j] = Keyframe;
animX = AnimationCurve(xs);
animY = AnimationCurve(ys);
}
}
function Update() {
transform.position = Vector3(animY.Evaluate(Time.time*1000),animX.Evaluate(Time.time*1000),0);
}