- Home /
Extension method not found
I have a file with an extension method that looks like this:
 using System.Collections;
 using UnityEngine;
 
 public static class ExtensionMethods {
     // converts vector3 to vector2, discarding the parameter marked by discard; 0: discard x, 1: discard y, 2: discard z
     public static Vector2 AsVector2(this Vector3 v3, int discard) {
         Vector2 v2 = new Vector2();
 
         if (discard == 0) {
             v2.x = v3.y;
             v2.y = v3.z;
         } else if (discard == 1) {
             v2.x = v3.x;
             v2.y = v3.z;
         } else if (discard == 2) {
             v2.x = v3.x;
             v2.y = v3.y;
         }
 
         return v2;
     }
 }
 
In of my scripts I try and use AsVector2 like this:
 Vector3 v3 = rigidbody.velocity;
 Vector2 v2 = v3.AsVector2(1);
However I get an error trying to do this: 'Vector3' does not contain a definition for 'AsVector2' and no accessible extension method 'AsVector2' accepting a first argument of type 'Vector3' could be found (are you missing a using directive or an assembly reference?) What am I doing incorrectly?
Answer by Esteem · Jan 18, 2020 at 10:52 PM
All I've got is you either have: 
 1. console compile errors
 2. the .cs file of extention methods in Editor folder
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to use extension classes 2 Answers
Renderer on object disabled after level reload 1 Answer
Texture2D Extension: Texture Still Null After Calling It 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                