Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Tekki-777 · Jun 20, 2017 at 03:51 AM · scripting problemerror message

Help with Error Code CS0019

So this excerpt of code is from my character controller script on line 34.

  private ControllerParameters2D Parameters { get { return _overrideParameters ?? DefaultParameters; } }

I'm getting a Error Code CS0019, stating, "Operator '??' cannot be applied to operands of type 'ControllerParameters2D' and 'ControllersParameters2D'"

I know this is also referring to the ControllerParameters2D script I made. The code is here below:

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 [Serializable]
 public class ControllersParameters2D
 {
     public enum JumpBehavior
     {
         CanJumpOnGround,
         CanJumpAnywhere,
         CantJump
     }
 
     public Vector2 MaxVelocity = new Vector2(float.MaxValue, float.MaxValue);
 
     [Range(0, 90)]
     public float SlopeLimit = 30;
 
     public float Gravity = -25f;
 
     public JumpBehavior JumpRestrictions;
 
     public float JumpFrequency = .25f;
 }


I'm very new to C# coding. I even copied this from the 9th video of the Creating a 2D Game in Unity 4.5 tutorial at Udemy. I know this code was originally for an older version of Unity and since I'm using Unity 5.6.1f1, I'm sure that some of the code is incompatible with the newer version.

Please help me and explain to me in depth the logic behind it.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hexagonius · Jun 21, 2017 at 05:24 AM 0
Share

Then you ned to explain what _overrideparameters and DefaultParameters are.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Tekki-777 · Jun 21, 2017 at 11:54 AM

I did. I should've posted that part of the code in the first place. :/

  public LayerMask PlatformMask;
     public ControllersParameters2D DefaultParameters;
     public ControllerState2D State { get; private set; }
 
     private readonly Vector2 velocity;
 
     public Vector2 GetVelocity()
     {
         return velocity;
     }
 
     public bool CanJump { get { return false; } }
     public bool HandleCollisions { get; set; }
     private ControllerParameters2D Parameters { get { return _overrideParameters ?? DefaultParameters; } }
 
     private Vector2 _velocity;
     private Transform _transform;
     private Vector3 _localScale;
     private BoxCollider2D _boxCollider;
     private ControllerParameters2D _overrideParameters;

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hexagonius · Jun 22, 2017 at 12:04 AM 0
Share

Is ControllersParameters2D a struct? If so, it won't work, it has to be a class ins$$anonymous$$d because it cannot be null.

avatar image Tekki-777 · Jun 22, 2017 at 02:55 AM 0
Share

Its already a public class, as seen with the ControllerParameters2D script. Here's the code (again).

  using System;
  using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  [Serializable]
  public class ControllersParameters2D
  {
      public enum JumpBehavior
      {
          CanJumpOnGround,
          CanJumpAnywhere,
          CantJump
      }
  
      public Vector2 $$anonymous$$axVelocity = new Vector2(float.$$anonymous$$axValue, float.$$anonymous$$axValue);
  
      [Range(0, 90)]
      public float SlopeLimit = 30;
  
      public float Gravity = -25f;
  
      public JumpBehavior JumpRestrictions;
  
      public float JumpFrequency = .25f;
  }

 
avatar image
0

Answer by hexagonius · Jun 22, 2017 at 11:49 AM

The problem is a mix of different classes here:

ControllerParameters2D and ControllersParameters2D

DefaultParameters is the latter where the return type of the property and _overrideParameters is the former.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

107 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Please Help Me: Assets/Scripts/PlayerControaller.cs(34,33): error CS8025: Parsing error 1 Answer

cannot convert type HealthandInventory to int 0 Answers

How do I fix "universul?" script problem 0 Answers

Object reference not set to an instance of an object - Jumping Scripts (C#) 1 Answer

I Need help with scripting a first person camera? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges