Rookie needs a pointer as to how to get my script for rotation a gameobject to work

58 views Asked by At

I've watched a lot of tutorials and i finally finished this code. I got it to rotate around its pivot point just fine but when i try to check for the gameobjects location on the Z axis to give it different commands according to its location it get stuck with this error message " Expression denotes a method group', where avariable', value' ortype' was expected".

What i am trying to accomplish is described further in the code. Here is the code i have so far, appreciate any pointers!

using UnityEngine;
using System.Collections;

public class KatanaAttacks : MonoBehaviour {

public float BackRotationsSpeed = 100f;
public float ForwardRotationSpeed = 300f;


// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {                                                                    // Rotation kan foregå på left right up down forward backwards

    if (Input.GetKey(KeyCode.U))                                                    // Origin location of sword (-1.523,86.914,8.212)                                   

    {

        if(transform.Rotate.z>8.2 && transform.Rotate.z<8.3)                        // Checks if sword is in its origin location, and when it is swings backwards
        {
                transform.Rotate(Vector3.forward, -BackRotationsSpeed * Time.deltaTime);        
        }


        if(transform.Rotate.z<200)                                                  // Checks if sword has reached furthest back point before swining forward + triple the speed swinging forward for extra oomf! 
        {
                transform.Rotate(Vector3.forward, ForwardRotationSpeed * Time.deltaTime);   
        }



        if(transform.Rotate.z>70)                                                    // Checks if sword has reached furthest forward point in the forward swing, if it is reset the rotation to its origin and wait for next attack command 
        {
                transform.Rotate (-1.523,86.914,8.212);
        }

}
}
}
1

There are 1 answers

1
Capsup On
if(transform.Rotate.z>8.2 && transform.Rotate.z<8.3)                        // Checks if sword is in its origin location, and when it is swings backwards

Here you're trying to use transform.Rotate as a object, which it isn't, it's a function.

I believe what you're actually interested in is transform.rotation.eulerangles: http://docs.unity3d.com/ScriptReference/Quaternion-eulerAngles.html

So:

if(transform.eulerAngles.z>8.2 && transform.eulerAngles.z<8.3)                        // Checks if sword is in its origin location, and when it is swings backwards