Home > Software design >  unity (c#) is showing the error whenever i add the script to the component
unity (c#) is showing the error whenever i add the script to the component

Time:05-05

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class EarthRotate : MonoBehaviour
{
    void Update()
    {
        gameObject.transform.Rotate(new vector3(0, 1, 0));
    }
}

Hello I am new to unity and c# as well but I am following well as far on the unity when it comes to c# scripting I am trying to follow every step correctly but every time I add the (c#) script in unity it shows me the error (error CS0246: The type or namespace name 'vector3' could not be found (are you missing a using directive or an assembly reference?))

I have tried adding different namespaces files and applied all the solutions available so far in my knowledge.

CodePudding user response:

You have to use this class, you have a typo in your code: https://docs.unity3d.com/ScriptReference/Vector3.html

As the comment from @DRapp suggests, try it with an uppercase "V".

This class is part of UnityEngine namespace, which you already included in your script.

CodePudding user response:

Your "new vector3(0, 1, 0)" should be written as "new Vector3(0, 1, 0)", the following is the introduction of Unity's Vector3 class

  1. Vector3 3D vector: represent 3D vectors and points. Contains information about position, orientation (orientation), Euler angles, and functions that do some common vector operations.
  2. Quaternion quaternion, used to represent rotation, Quaternion is used in Unity to represent all rotations. In computer graphics, it is used to represent the rotation of objects, and in Unity, four values ​​are represented by x, y, z, and w. Quaternions do not suffer from gimbal deadlock and can be easily interpolated. In Unity, the tranform component has a variable named rotation, and its type is quaternion.
  3. Euler angle: a set of 3 independent angle parameters used to determine the position of the fixed-point rotating rigid body, used to represent the rotation angle.

Declare a quaternion:

 Quaternion q1= this.transform.rotatiion;
 q1 = this.transform.rotation;

Declare Vector :

  Vector v1 =new Vector3(0,0,0);
  v1 = this.transform.eulerAngles; //Eulerian angle of Vector3

  Vector v2 =new Vector3(0,0,0);
  v2 = this.transform.position; //Vector3's position;

Vector3.normalized normalization

Non-static property; return value type vector3; return the unit vector with the same direction as the original vector, if the original vector is too small, return the zero vector;

Vector3.Normalize() normalization Static function; Return value type void; Return the unit vector with the same direction as the original vector, if the original vector is too small, return the zero vector;

  Vector3 v1 = this.transform.position.normalized;
  Vector3 v2 = Vector3.Normalize(this.transform.position);
  v1, v2 are equivalent.

vector3.magniude the length of the vector

Return the length of the vector, only the size, no direction, the return value type is float In fact, the length of the vector in the three-dimensional space is under the root sign (xx yy z*z)

Vector3.SqrMagnitude vector length squared

Often used for vector comparisons, because computer squaring and square root comparisons consume memory and time. There are also some that need to be found online.

  • Related