Forum begins after the advertisement:


[Part 3] Knife spawns but doesn’t move

Home › Forums › Video Game Tutorial Series › Creating a Rogue-like Shoot-em Up in Unity › [Part 3] Knife spawns but doesn’t move

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #12759
    Renaud St-Hilaire
    Level 19
    Former Patron
    Helpful?
    Up
    0
    ::

    Hi, I have a problem with the knife movement, the knife spawns but doent move, I went over the code and compared it with project files and its the same, I get a NullreferenceException error in the knife behaviour script, I watche the null reference troubleshooting video and it didnt help, can someone point me in the right direction? The error is on the line 21.

    <blockquote class=”imgur-embed-pub” lang=”en” data-id=”a/Iud8xWA”><a href=”https://imgur.com/a/Iud8xWA” target=”_blank”>View post on imgur.com</a></blockquote><script async src=”//s.imgur.com/min/embed.js” charset=”utf-8″></script>

    #12761
    Terence
    Level 32
    Keymaster
    Helpful?
    Up
    0
    ::

    Hey Renaud, you are calling the wrong function in Start(). It should be <code>FindObjectOfType()</code>, not <code>GetComponent()</code>.

    <pre>protected override void Start() { base.Start(); kc = <del>GetComponent</del><mark class=”green”>FindObjectOfType</mark><KnifeController>(); }</pre>

    Your issue is because <code>kc</code> is null, so when your code accesses <code>kc.speed</code> in <code>Update()</code>, you are essentially doing <code>null.speed</code>, which causes the null reference exception.

    #12762
    Renaud St-Hilaire
    Level 19
    Former Patron
    Helpful?
    Up
    0
    ::

    It works! Thank you so much! I love your tutorials!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: