- Home /
Script Errors
Use Unity Pro 4.3.0f4
Script #1
renderer.material.mainTexture.Play();
Error #1
Assets/PlayVideo.js(1,31): BCE0019: 'Play' is not a member of 'UnityEngine.Texture'.
Script #2
private var timer = 0.0;
var bobbingSpeed = 0.18;
var bobbingAmount = 0.2;
var midpoint = 2.0;
function Update () {
waveslice = 0.0;
horizontal = Input.GetAxis("Horizontal");
vertical = Input.GetAxis("Vertical");
if (Mathf.Abs(horizontal) == 0 && Mathf.Abs(vertical) == 0) {
timer = 0.0;
}
else {
waveslice = Mathf.Sin(timer);
timer = timer + bobbingSpeed;
if (timer > Mathf.PI * 2) {
timer = timer - (Mathf.PI * 2);
}
}
if (waveslice != 0) {
translateChange = waveslice * bobbingAmount;
totalAxes = Mathf.Abs(horizontal) + Mathf.Abs(vertical);
totalAxes = Mathf.Clamp (totalAxes, 0.0, 1.0);
translateChange = totalAxes * translateChange;
transform.localPosition.y = midpoint + translateChange;
}
else {
transform.localPosition.y = midpoint;
}
}
SO MANY ERRORS
I tried it on old version and it's working .. You have any idea what's the correct then for this version?
Oh, it's a movie texture. I don't have Pro so I haven't had the chance to use those. You can play a $$anonymous$$ovieTexture but not a Texture. It may be that renderer.material.mainTexture returns type Texture even if it is a $$anonymous$$ovieTexture. So, I think you first have to have a variable of type $$anonymous$$ovieTexture, then you have to assign that $$anonymous$$ovieTexture to the renderer.material, then you can tell your $$anonymous$$ovieTexture variable to Play() directly.
If you want help you should explain what you're trying to do... As the error states, a Texture2D doesn't have a Play()
method, so whatever you're trying to do in that first command, you're doing it wrong.
And the second script, you're trying to set many variables but you haven't defined any of them. Try adding var
before each variable the first time that you use it.
And I do recommend starting with some Javascript tutorials since this is pretty basic stuff. W3Schools has a good one: http://www.w3schools.com/js/
You guys said add "var" before variable but there is
private var timer = 0.0;
var bobbingSpeed = 0.18;
var bobbingAmount = 0.2;
var midpoint = 2.0;
Answer by Kiloblargh · Dec 15, 2013 at 06:51 AM
"Unknown Identifier" means you use a variable name that you have not declared. In Javascript / Unityscript, you must add the "`var`" keyword to declare a variable before you can assign a value to it. But don't do that in Update(). Declare them before the function in which you use them or at the top of your script.
Textures cannot be played. "Is not a member of" basically means you are trying to tell an object to do something that isn't something that kind of object does.
Thanks for the comment but do you know the correct script to play video?
Idk why but Unity is actually dicking with me ...
http://docs.unity3d.com/Documentation/$$anonymous$$anual/VideoFiles.html
Exact same script I use in my game .. It's working on previous version but not in this version =='
Also from the docs: Note: If you have #pragma strict enabled in your code a $$anonymous$$ovieTexture object should be declared somewhere and the object should be initialized with renderer.material.mainTexture. Then isPlaying, Play() and Stop() should be called for this $$anonymous$$ovieTexture object.
In days of old, #pragma strict
was optional. You could omit it and write sloppy code that would still compile at the expense of performance. Now, Unityscript is a lot more of a stickler for types, and if you're used to web JavaScript, which only infers types dynamically, you have to re-learn some things.
You should be writing, for example, var bobbingSpeed : float = 0.18;
. For floats, it's not necessary, but for some things it is, and if you're in the habit of always putting a type after a variable, you will stay out of trouble.