Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Other help i cannot find anything on this.

Discussion in 'Scripting' started by squeaker091, Apr 6, 2023.

  1. squeaker091

    squeaker091

    Joined:
    Mar 20, 2023
    Posts:
    23
    hi im really confused because i was using a Dave game developer video about costume projectiles and it said in my error thing that. camera does not have a definition for ViewportPointToRay. I've looked it up but found nothing. this is the only error in my script, and it will not go away please help. I really want guns for my game, and this is stopping me :(
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,951
    Remember: NOBODY here memorizes error codes. That's not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

    The complete error message contains everything you need to know to fix the error yourself.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly?

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.

    Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

    How to do tutorials properly, two (2) simple steps to success:

    Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That's how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.

    Fortunately this is the easiest part to get right: Be a robot. Don't make any mistakes.
    BE PERFECT IN EVERYTHING YOU DO HERE!!


    If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

    Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

    Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

    Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there's an error, you will NEVER be the first guy to find it.

    Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!

    Finally, when you have errors, don't post here... just go fix your errors! See above.
     
  3. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    717
    It's hard to intuit what is wrong with your code when we cannot see it...

    That said, perhaps, you're doing this?

    Code (CSharp):
    1. Camera.ViewportPointToRay
    ViewportPointToRay is an instance method, and can only be called on a specific instance of a camera, rather than the Camera class itself. So, you'd probably want to do this, instead:

    Code (CSharp):
    1. Camera.main.ViewportPointToRay
    ...since
    Camera.main
    is the main camera (and thus a specific camera, that you can ask to convert a viewport point into a ray!)

    However, the error you quoted -- "X does not contain a definition for Y" -- would not appear in this situation. You'd see an error like "An object reference is required for the non-static field, method, or property [...]".

    So, show your code, please.
     
  4. squeaker091

    squeaker091

    Joined:
    Mar 20, 2023
    Posts:
    23
    ok look up Dave / game development on YouTube and go into the tutorials playlist and it is the first video that says about costume projectiles. there's two parts but parts one is about just shooting. I even downloaded the code, and I still did not get the error so go away. and Kurt... NOT HELPING, I MIGHT BE NEW AT THIS BUT IM NOT STUPID. I LOOKED THROUGH THE VIDEO 5 TIMES. AND I KNOW THIS STUFF I DO MY RESEARCH. I HAVE NO IDEA WHY MY EDITOR IS SAYING ITS WRONG. IT DID THIS WITH A "FieldOfView" STATMENT AND IT WAS WRONG THERE TOO. AND I LOOK AT ALL THE UNITY DOCUMENTATION AND OTHER STUFF BUT NOTHING WORKS. I'm really mad and I do not need this right now. and i do not know how to show code on forms. I'm new to these forms too.
     
    Last edited: Apr 6, 2023
  5. StarBornMoonBeam

    StarBornMoonBeam

    Joined:
    Mar 26, 2023
    Posts:
    209
    Calm down, take an hour break. Come back to it The chemical has answered your question. Just take a load off the stress and come back 1 hour. What’s 1 hour. It’s time to de-stress.
    He has answered the question. You are just so frustrated right now you can’t see that. (YouTube Tutorials do that, they frustrate, because the guy is milking your time consuming your life)

    To do a viewpoint ray from the camera the camera needs to be referenced either as Camera.main, or - by dragging a game object with a camera into your inspector with your script.

    Do us a favour when you get back from your break, and screenshot your inspector with the script. To use code tags there is a small written Code: with an image. 7F88480A-E7CA-43CC-8779-6E705C2DFB9F.jpeg
    it’s on the right hand side near the floppy disc icon.
     
    lordofduct likes this.
  6. squeaker091

    squeaker091

    Joined:
    Mar 20, 2023
    Posts:
    23
    ok so i do have a public camera. i can put it in the inspector. or if it worked i could and heres my code

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using TMPro;
    4.  
    5. /// Thanks for downloading my projectile gun script! :D
    6. /// Feel free to use it in any project you like!
    7. ///
    8. /// The code is fully commented but if you still have any questions
    9. /// don't hesitate to write a yt comment
    10. /// or use the #coding-problems channel of my discord server
    11. ///
    12. /// Dave
    13. public class ProjectileGunTutorial : MonoBehaviour
    14. {
    15.     //bullet
    16.     public GameObject bullet;
    17.  
    18.     //bullet force
    19.     public float shootForce, upwardForce;
    20.  
    21.     //Gun stats
    22.     public float timeBetweenShooting, spread, reloadTime, timeBetweenShots;
    23.     public int magazineSize, bulletsPerTap;
    24.     public bool allowButtonHold;
    25.  
    26.     int bulletsLeft, bulletsShot;
    27.  
    28.     //Recoil
    29.     public Rigidbody playerRb;
    30.     public float recoilForce;
    31.  
    32.     //bools
    33.     bool shooting, readyToShoot, reloading;
    34.  
    35.     //Reference
    36.     public Camera fpsCam;
    37.     public Transform attackPoint;
    38.  
    39.     //Graphics
    40.     public GameObject muzzleFlash;
    41.     public TextMeshProUGUI ammunitionDisplay;
    42.  
    43.     //bug fixing :D
    44.     public bool allowInvoke = true;
    45.  
    46.     private void Awake()
    47.     {
    48.         //make sure magazine is full
    49.         bulletsLeft = magazineSize;
    50.         readyToShoot = true;
    51.     }
    52.  
    53.     private void Update()
    54.     {
    55.         MyInput();
    56.  
    57.         //Set ammo display, if it exists :D
    58.         if (ammunitionDisplay != null)
    59.             ammunitionDisplay.SetText(bulletsLeft / bulletsPerTap + " / " + magazineSize / bulletsPerTap);
    60.     }
    61.     private void MyInput()
    62.     {
    63.         //Check if allowed to hold down button and take corresponding input
    64.         if (allowButtonHold) shooting = Input.GetKey(KeyCode.Mouse0);
    65.         else shooting = Input.GetKeyDown(KeyCode.Mouse0);
    66.  
    67.         //Reloading
    68.         if (Input.GetKeyDown(KeyCode.R) && bulletsLeft < magazineSize && !reloading) Reload();
    69.         //Reload automatically when trying to shoot without ammo
    70.         if (readyToShoot && shooting && !reloading && bulletsLeft <= 0) Reload();
    71.  
    72.         //Shooting
    73.         if (readyToShoot && shooting && !reloading && bulletsLeft > 0)
    74.         {
    75.             //Set bullets shot to 0
    76.             bulletsShot = 0;
    77.  
    78.             Shoot();
    79.         }
    80.     }
    81.  
    82.     private void Shoot()
    83.     {
    84.         readyToShoot = false;
    85.  
    86.         //Find the exact hit position using a raycast
    87.         Ray ray = fpsCam.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0)); //Just a ray through the middle of your current view
    88.         RaycastHit hit;
    89.  
    90.         //check if ray hits something
    91.         Vector3 targetPoint;
    92.         if (Physics.Raycast(ray, out hit))
    93.             targetPoint = hit.point;
    94.         else
    95.             targetPoint = ray.GetPoint(75); //Just a point far away from the player
    96.  
    97.         //Calculate direction from attackPoint to targetPoint
    98.         Vector3 directionWithoutSpread = targetPoint - attackPoint.position;
    99.  
    100.         //Calculate spread
    101.         float x = Random.Range(-spread, spread);
    102.         float y = Random.Range(-spread, spread);
    103.  
    104.         //Calculate new direction with spread
    105.         Vector3 directionWithSpread = directionWithoutSpread + new Vector3(x, y, 0); //Just add spread to last direction
    106.  
    107.         //Instantiate bullet/projectile
    108.         GameObject currentBullet = Instantiate(bullet, attackPoint.position, Quaternion.identity); //store instantiated bullet in currentBullet
    109.         //Rotate bullet to shoot direction
    110.         currentBullet.transform.forward = directionWithSpread.normalized;
    111.  
    112.         //Add forces to bullet
    113.         currentBullet.GetComponent<Rigidbody>().AddForce(directionWithSpread.normalized * shootForce, ForceMode.Impulse);
    114.         currentBullet.GetComponent<Rigidbody>().AddForce(fpsCam.transform.up * upwardForce, ForceMode.Impulse);
    115.  
    116.         //Instantiate muzzle flash, if you have one
    117.         if (muzzleFlash != null)
    118.             Instantiate(muzzleFlash, attackPoint.position, Quaternion.identity);
    119.  
    120.         bulletsLeft--;
    121.         bulletsShot++;
    122.  
    123.         //Invoke resetShot function (if not already invoked), with your timeBetweenShooting
    124.         if (allowInvoke)
    125.         {
    126.             Invoke("ResetShot", timeBetweenShooting);
    127.             allowInvoke = false;
    128.  
    129.             //Add recoil to player (should only be called once)
    130.             playerRb.AddForce(-directionWithSpread.normalized * recoilForce, ForceMode.Impulse);
    131.         }
    132.  
    133.         //if more than one bulletsPerTap make sure to repeat shoot function
    134.         if (bulletsShot < bulletsPerTap && bulletsLeft > 0)
    135.             Invoke("Shoot", timeBetweenShots);
    136.     }
    137.     private void ResetShot()
    138.     {
    139.         //Allow shooting and invoking again
    140.         readyToShoot = true;
    141.         allowInvoke = true;
    142.     }
    143.  
    144.     private void Reload()
    145.     {
    146.         reloading = true;
    147.         Invoke("ReloadFinished", reloadTime); //Invoke ReloadFinished function with your reloadTime as delay
    148.     }
    149.     private void ReloadFinished()
    150.     {
    151.         //Fill magazine
    152.         bulletsLeft = magazineSize;
    153.         reloading = false;
    154.     }
    155. }
    i did download this. but only after i could not find my mistake.
     
  7. squeaker091

    squeaker091

    Joined:
    Mar 20, 2023
    Posts:
    23
    i am claim now. i played some Minecraft and feel better. also that one guy just sounded really rude. also i did what he said. and still nothing. but pls tell me whats wrong with my code
     
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,951
    You seem perhaps confused about how this works.

    How to report your problem productively in the Unity3D forums:

    http://plbm.com/?p=220

    This is the bare minimum of information to report:

    - what you want
    - what you tried
    - what you expected to happen
    - what actually happened, log output, variable values, and especially any errors you see
    - links to documentation you used to cross-check your work (CRITICAL!!!)
     
  9. StarBornMoonBeam

    StarBornMoonBeam

    Joined:
    Mar 26, 2023
    Posts:
    209
    thescript.png

    I got your script to work myself

    public class PROJECTILEGUNTUTORIAL : MonoBehaviour

    when you created your script in unity project folder if you named the script anything other than the intended name then the inspector wont display it.

    When i made the script i named it PROJECTILEGUNTUTORIAL in all caps. But the original is ProjectileGunTutorial, if you created the script and removed from the cs file name ProjectileGunTutorial then none of your variables or objects can be set in that inspector.

    As you see the inspector you'll end up with when you fix this, you can drag the camera in. I had to remove TMPRO references in my version because i don't use text mesh pro, and the assemblie definitions are not in my project.

    SO MAKE SURE!!!!!! YOU TITLED YOUR SCRIPT TO WHATEVER IS WRITTEN WHEN THE CLASS IS SPECIFIED :)

    sol.png

    make sure that public class is referencing the correct name of the script you created. Without the .cs on the end

    No problem with the Viewport unless those names didn't match.

    Let us know how you get on fella.
     
  10. squeaker091

    squeaker091

    Joined:
    Mar 20, 2023
    Posts:
    23
    ok thanks but just pls help me. i will remember that for next time
     
  11. squeaker091

    squeaker091

    Joined:
    Mar 20, 2023
    Posts:
    23
    ok umm... i tried your suggestion and it did not work? I'm confused a lot now. I've redownloaded it then changed the name but. it still says no scripts are there, I'm goanna try the tutorial again. maybe i can fix it? I hate that I'm doing the tutorial for the 6th time now.
     
  12. StarBornMoonBeam

    StarBornMoonBeam

    Joined:
    Mar 26, 2023
    Posts:
    209
    Code (CSharp):
    1. using UnityEngine;
    2. //using TMPro;
    3.  
    4. /// Thanks for downloading my projectile gun script! :D
    5. /// Feel free to use it in any project you like!
    6. ///
    7. /// The code is fully commented but if you still have any questions
    8. /// don't hesitate to write a yt comment
    9. /// or use the #coding-problems channel of my discord server
    10. ///
    11. /// Dave
    12. public class ProjectileGunTutorial : MonoBehaviour
    13. {
    14.     //bullet
    15.     public GameObject bullet;
    16.  
    17.     //bullet force
    18.     public float shootForce, upwardForce;
    19.  
    20.     //Gun stats
    21.     public float timeBetweenShooting, spread, reloadTime, timeBetweenShots;
    22.     public int magazineSize, bulletsPerTap;
    23.     public bool allowButtonHold;
    24.  
    25.     int bulletsLeft, bulletsShot;
    26.  
    27.     //Recoil
    28.     public Rigidbody playerRb;
    29.     public float recoilForce;
    30.  
    31.     //bools
    32.     bool shooting, readyToShoot, reloading;
    33.  
    34.     //Reference
    35.     public Camera fpsCam;
    36.     public Transform attackPoint;
    37.  
    38.     //Graphics
    39.     public GameObject muzzleFlash;
    40.     //public TextMeshProUGUI ammunitionDisplay;
    41.  
    42.     //bug fixing :D
    43.     public bool allowInvoke = true;
    44.  
    45.     private void Awake()
    46.     {
    47.         //make sure magazine is full
    48.         bulletsLeft = magazineSize;
    49.         readyToShoot = true;
    50.     }
    51.  
    52.     private void Update()
    53.     {
    54.         MyInput();
    55.  
    56.         //Set ammo display, if it exists :D
    57.         //if (ammunitionDisplay != null)
    58.         //    ammunitionDisplay.SetText(bulletsLeft / bulletsPerTap + " / " + magazineSize / bulletsPerTap);
    59.     }
    60.     private void MyInput()
    61.     {
    62.         //Check if allowed to hold down button and take corresponding input
    63.         if (allowButtonHold) shooting = Input.GetKey(KeyCode.Mouse0);
    64.         else shooting = Input.GetKeyDown(KeyCode.Mouse0);
    65.  
    66.         //Reloading
    67.         if (Input.GetKeyDown(KeyCode.R) && bulletsLeft < magazineSize && !reloading) Reload();
    68.         //Reload automatically when trying to shoot without ammo
    69.         if (readyToShoot && shooting && !reloading && bulletsLeft <= 0) Reload();
    70.  
    71.         //Shooting
    72.         if (readyToShoot && shooting && !reloading && bulletsLeft > 0)
    73.         {
    74.             //Set bullets shot to 0
    75.             bulletsShot = 0;
    76.  
    77.             Shoot();
    78.         }
    79.     }
    80.  
    81.     private void Shoot()
    82.     {
    83.         readyToShoot = false;
    84.  
    85.         //Find the exact hit position using a raycast
    86.         Ray ray = fpsCam.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0)); //Just a ray through the middle of your current view
    87.         RaycastHit hit;
    88.  
    89.         //check if ray hits something
    90.         Vector3 targetPoint;
    91.         if (Physics.Raycast(ray, out hit))
    92.             targetPoint = hit.point;
    93.         else
    94.             targetPoint = ray.GetPoint(75); //Just a point far away from the player
    95.  
    96.         //Calculate direction from attackPoint to targetPoint
    97.         Vector3 directionWithoutSpread = targetPoint - attackPoint.position;
    98.  
    99.         //Calculate spread
    100.         float x = Random.Range(-spread, spread);
    101.         float y = Random.Range(-spread, spread);
    102.  
    103.         //Calculate new direction with spread
    104.         Vector3 directionWithSpread = directionWithoutSpread + new Vector3(x, y, 0); //Just add spread to last direction
    105.  
    106.         //Instantiate bullet/projectile
    107.         GameObject currentBullet = Instantiate(bullet, attackPoint.position, Quaternion.identity); //store instantiated bullet in currentBullet
    108.         //Rotate bullet to shoot direction
    109.         currentBullet.transform.forward = directionWithSpread.normalized;
    110.  
    111.         //Add forces to bullet
    112.         currentBullet.GetComponent<Rigidbody>().AddForce(directionWithSpread.normalized * shootForce, ForceMode.Impulse);
    113.         currentBullet.GetComponent<Rigidbody>().AddForce(fpsCam.transform.up * upwardForce, ForceMode.Impulse);
    114.  
    115.         //Instantiate muzzle flash, if you have one
    116.         if (muzzleFlash != null)
    117.             Instantiate(muzzleFlash, attackPoint.position, Quaternion.identity);
    118.  
    119.         bulletsLeft--;
    120.         bulletsShot++;
    121.  
    122.         //Invoke resetShot function (if not already invoked), with your timeBetweenShooting
    123.         if (allowInvoke)
    124.         {
    125.             Invoke("ResetShot", timeBetweenShooting);
    126.             allowInvoke = false;
    127.  
    128.             //Add recoil to player (should only be called once)
    129.             playerRb.AddForce(-directionWithSpread.normalized * recoilForce, ForceMode.Impulse);
    130.         }
    131.  
    132.         //if more than one bulletsPerTap make sure to repeat shoot function
    133.         if (bulletsShot < bulletsPerTap && bulletsLeft > 0)
    134.             Invoke("Shoot", timeBetweenShots);
    135.     }
    136.     private void ResetShot()
    137.     {
    138.         //Allow shooting and invoking again
    139.         readyToShoot = true;
    140.         allowInvoke = true;
    141.     }
    142.  
    143.     private void Reload()
    144.     {
    145.         reloading = true;
    146.         Invoke("ReloadFinished", reloadTime); //Invoke ReloadFinished function with your reloadTime as delay
    147.     }
    148.     private void ReloadFinished()
    149.     {
    150.         //Fill magazine
    151.         bulletsLeft = magazineSize;
    152.         reloading = false;
    153.     }
    154. }
    Thats all i did. make sure the name of the file in the folder matches the Class name whichever way around will work. My version, i did not delete lines! but i // commented out TM pro, which is only one line in update to display ammo count using a text asset.


    if your script in inspector looks like this! then the names of class and file do not match.
    namesdontmatch.png
     
    Last edited: Apr 7, 2023
  13. squeaker091

    squeaker091

    Joined:
    Mar 20, 2023
    Posts:
    23
    umm it had the speech bubble and I tried without that stuff at the top but nothing. I'm doing the tutorial over so it might work. if not, I give up. btw I'm on 2021.3 if that makes a difference.
     
  14. StarBornMoonBeam

    StarBornMoonBeam

    Joined:
    Mar 26, 2023
    Posts:
    209
    >.<

    ProjectileGunTutorial

    just rename the script in the project folder to ProjectileGunTutorial, it will work as is. 2021.3 is what I’m on as well.
     
  15. squeaker091

    squeaker091

    Joined:
    Mar 20, 2023
    Posts:
    23
    umm I tried that like you said. but... it did not work. :( I'm trying everything. and it's still coming up btw. I got to the part where the codes put in. and BOOM, error. also, I had problems with cam stuff before.
     
  16. squeaker091

    squeaker091

    Joined:
    Mar 20, 2023
    Posts:
    23
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using TMPro;
    5.  
    6. public class projectilegunscript : MonoBehaviour
    7. {
    8.    public GameObject bullet;
    9.  
    10.    public float shootForce, upwardForce;
    11.  
    12.    public float timeBetweenShooting, spread, reloadTime, timeBetweenShots;
    13.    public int magazineSize, bulletsPerTap;
    14.    public bool allowButtonHold;
    15.    int bulletsLeft, bulletsShot;
    16.  
    17.    bool shooting, readyToShoot, reloading;
    18.  
    19.    public Camera fpsCam;
    20.    public Transform attackPoint;
    21.  
    22.    public bool allowInvoke = true;
    23.  
    24.    private void Awake()
    25.    {
    26.         bulletsLeft = magazineSize;
    27.         readyToShoot = true;
    28.    }
    29.  
    30.    private void Update()
    31.    {
    32.         MyInput();
    33.    }
    34.  
    35.    private void MyInput()
    36.    {
    37.         if (allowButtonHold) shooting = Input.GetKey(KeyCode.Mouse0);
    38.         else shooting = Input.GetKeyDown(KeyCode.Mouse0);
    39.  
    40.         if (readyToShoot && shooting && !reloading && bulletsLeft > 0)
    41.         {
    42.             bulletsShot = 0;
    43.  
    44.             Shoot();
    45.         }
    46.    }
    47.  
    48.    private void Shoot()
    49.    {
    50.         readyToShoot = false;
    51.  
    52.         Ray ray = fpsCam.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
    53.         RaycastHit hit;
    54.  
    55.         Vector3 targetPoint;
    56.         if (Physics.Raycast(ray, out hit))
    57.             targetPoint = hit.point;
    58.         else
    59.             targetPoint = ray.GetPoint(75);
    60.        
    61.         Vector3 directionWithoutSpread = targetPoint - attackPoint.position;
    62.  
    63.         float x = Random.Range(-spread, spread);
    64.         float y = Random.Range(-spread, spread);
    65.  
    66.         Vector3 directionWithSpread = directionWithoutSpread + new Vector3(x, y, 0);
    67.  
    68.         bulletsLeft--;
    69.         bulletsShot++;
    70.    }
    71. }


    this is where i am so far. and i got the error
     
  17. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    717
    You need to be more specific. Provide the exact error you are getting. Give the line number and the file name. Is it the same as before, or has something changed?

    "It did not work" is not helpful. We can't do anything with that.
     
  18. squeaker091

    squeaker091

    Joined:
    Mar 20, 2023
    Posts:
    23
    "It did not work" is not helpful. We can't do anything with that.[/QUOTE]


    Assets\projectilegunscript.cs(52,26): error CS1061: 'Camera' does not contain a definition for 'ViewportPointToRay' and no accessible extension method 'ViewportPointToRay' accepting a first argument of type 'Camera' could be found (are you missing a using directive or an assembly reference?)
     
  19. squeaker091

    squeaker091

    Joined:
    Mar 20, 2023
    Posts:
    23
    there you go
     
  20. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,951
    Did you make your own script called
    Camera
    ? If so , don't do that.
     
    StarBornMoonBeam likes this.
  21. squeaker091

    squeaker091

    Joined:
    Mar 20, 2023
    Posts:
    23

    ummm i did. should i change it
     
    Kurt-Dekker likes this.
  22. squeaker091

    squeaker091

    Joined:
    Mar 20, 2023
    Posts:
    23
    im watching some dave game developer vidios and i did his most updated movement script which had that script
     
  23. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    717
    Ah, yes, there is your issue.

    It's finding your class called "Camera", then getting confused because it can't find the method it's expecting to find.

    You should rename your class to something else.

    I do this from time to time. It can be very confusing.
     
    StarBornMoonBeam likes this.
  24. squeaker091

    squeaker091

    Joined:
    Mar 20, 2023
    Posts:
    23
    great just great. i have to redo the hole camera. UGGGGG. i have to becuase i cannot just get it to change its self so i can copie and paste the code into a new script.
     
  25. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    717
    You can just...rename the class and the file it's contained in.
     
  26. squeaker091

    squeaker091

    Joined:
    Mar 20, 2023
    Posts:
    23
    ok im not going to reply until tomorrow so bye. but i am loving the help
     
  27. StarBornMoonBeam

    StarBornMoonBeam

    Joined:
    Mar 26, 2023
    Posts:
    209
    Well for the record if you start a new project the weapon script will work. But if that means losing his character controller and custom camera well, you can use the Unity provided ones which should be more than suitable for doing your first first person shooter (if that’s what you’re doing)
     
  28. squeaker091

    squeaker091

    Joined:
    Mar 20, 2023
    Posts:
    23
    i tried and everything got screwed up.
     
  29. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,951
    If you think renaming a file is hard, you'll really love this stuff:

    Camera stuff is pretty tricky... you may wish to consider using Cinemachine from the Unity Package Manager.

    There's even a dedicated forum: https://forum.unity.com/forums/cinemachine.136/
     
  30. squeaker091

    squeaker091

    Joined:
    Mar 20, 2023
    Posts:
    23
    oh nononono im just going to delet the files and make new ones. i can work that way
     
  31. squeaker091

    squeaker091

    Joined:
    Mar 20, 2023
    Posts:
    23

    i know about the cinemachine but i am just going to use the script i have.
     
  32. squeaker091

    squeaker091

    Joined:
    Mar 20, 2023
    Posts:
    23
    uhhh my Tilt now does not work. i think i have to do the hole project over again. :(. i renamed it but just nothing. and now my wall running script is not working either.