Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Ochreous · Apr 16, 2014 at 08:58 PM · c#transform

C# Transform Issues

I'm trying to convert a Unityscript script into a C# script. I'm getting several errors with the transforms but I'm not sure why. I have the transforms stored in Player so I don't why it keeps telling me to store it in another variable when I already have. What is wrong with my script? I have commented out the the lines of code that are causing these errors.

 using UnityEngine;
 using System.Collections;
 
 public class NewFullyDynamicParkour : MonoBehaviour {
 
     public float ClimbMax;
     public float VaultMax;
     public float VaultMin;
     public float distanceToGoFwd = 0.7f;
     private bool CanVault;
     private bool CanClimb;
     private float DistancePlRayFwd;
     private float DistancePlRayUp;
     private Transform Player;
     private CharacterController charCont;
     private bool CanParkour;
     public bool EnableRoll;
     public float lastPos;
     public string Roll;
     public float HeightToRoll = 25;
     private bool canRoll;
     public float distanceDamage = 55;
     public float maxFall;
     private float max;
     public GameObject CheckRay;
     public float range;
     private float maxH;
     public bool Translate;
     
     void Start()
     {
         Player = transform.gameObject.transform;
         charCont = Player.GetComponent<CharacterController>();
     }
     
     void Update () 
     {
         if(CanParkour || charCont.isGrounded == false)
             Translate  = true;
         else
             Translate = false;
         maxH = Mathf.Abs(max - Player.transform.position.y + charCont.height/2);
         Debug.Log(maxH);
         CharacterController charContr = Player.GetComponent<CharacterController>();
         float radius = charCont.radius;
         Vector3 p1 = transform.position + charCont.center;
         Vector3 p2 = p1;
         p2.y += VaultMax;
         p1.y -= charCont.height/2f + 0.02f;
         if (Physics.CapsuleCast(p1, p2, radius, transform.forward, range))
         {
             if(!Physics.Raycast(transform.position, transform.TransformDirection (Vector3.forward), 0.7f))
             {
                 if(!CanParkour)
                 {
                     if(Input.GetKeyDown(KeyCode.V))
                     {
                         //Player.transform.position.y = CheckRay.transform.position.y + charCont.height + 0.1f;
                         Player.transform.Translate(0, 0, distanceToGoFwd + 0.3f);
                     }
                 }
             }
             if(Physics.Raycast(CheckRay.transform.position, transform.TransformDirection (Vector3.forward), 0.7f))
             {
                 CheckRay.transform.Translate(0, 8 * Time.deltaTime, 0);
                 max = Mathf.Max(max, CheckRay.transform.position.y);
             }
             if(maxH < ClimbMax)
             {
                 Changing();
             }
             else
                 CanParkour = false;
             if(maxH >= VaultMax)
             {
                 CanVault = false;
                 CanClimb = true;
             }
             else
             {
                 CanVault = true;
                 CanClimb = false;
             }
         }
         else
         {
             CanParkour = false;
             max = 0;
             CheckRay.transform.position = new Vector3(CheckRay.transform.position.x, Player.transform.position.y, CheckRay.transform.position.z);
         }
         if(CanParkour)
         {
             if(CanVault == true)
             {
                 if(Input.GetKeyDown(KeyCode.V))
                 {
                     Vault();
                 }
             }
             if(CanClimb == true)
             {
                 if(Input.GetKeyDown(KeyCode.V))
                 {
                     Climb();
                 }
             }
         }
         if(EnableRoll)
         {
             if(!charCont.isGrounded)
                 maxFall = Mathf.Max(Mathf.Abs(charCont.transform.position.y), maxFall);
             else
                 lastPos = charCont.transform.position.y;
             if(charCont.isGrounded) {
                 if(maxFall - lastPos > HeightToRoll){
                     if(maxFall - lastPos > distanceDamage)
                     {
                         Player.transform.SendMessageUpwards("GetBulletDamage", maxFall + distanceDamage*2, SendMessageOptions.DontRequireReceiver);
                     }
                     maxFall = 0;
                 }
             }
         }
     }
     
     IEnumerator Vault()
     {
         float upDist = CheckRay.transform.position.y + 0.2f;
         float fwdDist = distanceToGoFwd;
         Vector3 endPos = new Vector3(Player.transform.position.x, upDist, fwdDist);
         Player.transform.position = Vector3.MoveTowards(Player.transform.position, endPos, 5 * Time.deltaTime);
         yield return new WaitForSeconds(distanceToGoFwd);
         Translate = false;
     }
     
     void Climb()
     {
         //Player.transform.position.y = CheckRay.transform.position.y + charCont.height + 0.1f;
         Player.transform.Translate(0, 0, distanceToGoFwd + 0.3f);
         Translate = false;
     }
     
     IEnumerator Changing()
     {
         yield return new WaitForSeconds(0.3f);
         CanParkour = true;
     }
 }
 
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by fendorio · Apr 16, 2014 at 09:07 PM

Since you just dumped your script I cba to describe where to find this. Do a simple ctrl+F

     else
     {
         CanParkour = false;
         max = 0;
         CheckRay.transform.position = Vector3(CheckRay.transform.position.x, Player.transform.position.y, CheckRay.transform.position.z);
     }

This line:

 CheckRay.transform.position = Vector3(CheckRay.transform.position.x,
                         Player.transform.position.y, CheckRay.transform.position.z);

You need to add the new keyword before Vector3, transform.position = a new Vector3.

So should be:

 CheckRay.transform.position = new Vector3(CheckRay.transform.position.x,
                         Player.transform.position.y, CheckRay.transform.position.z);

With that correction I've got it to compile.

Comment
Add comment · Show 9 · 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 Ochreous · Apr 16, 2014 at 09:17 PM 0
Share

That fixed one error but what about the others? Here's a list of the other lines of code that were giving errors.

 //Player.transform.position.y = CheckRay.transform.position.y + charCont.height + 0.1f;
 //Vector3 endPos = Vector3(Player.transform.position.x, upDist, fwdDist);
 //Player.transform.position.y = CheckRay.transform.position.y + charCont.height + 0.1f;
avatar image fendorio · Apr 16, 2014 at 09:19 PM 0
Share

Ok come on lol use your head:

 Vector3 endPos = Vector3(Player.transform.position.x, upDist, fwdDist);

Exactly the same error as before. Use the new keyword.

avatar image fendorio · Apr 16, 2014 at 09:21 PM 0
Share

Is CheckRay assigned to in the editor? You make no assignment to that GameObject in the script so presumably it's null.

avatar image Ochreous · Apr 16, 2014 at 09:47 PM 0
Share

Yes CheckRay is assigned to in the editor. So that solves the vector3s. What about the player.transform.position.y?

 //Player.transform.position.y = CheckRay.transform.position.y + charCont.height + 0.1f;
 //Player.transform.position.y = CheckRay.transform.position.y + charCont.height + 0.1f;
avatar image fendorio · Apr 16, 2014 at 09:57 PM 0
Share

Although not the most elegant solution this will fix your problem:

 var number = CheckRay.transform.position.y + charCont.height + 0.1f;
 Player.transform.position.y = number;

So assign the sum of to a variable, then assign that variable to the transform.position.y.

Vote and accept if it helped :P

Btw the two errors are the same, so apply that to both of them :)

Show more comments

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

20 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

Related Questions

C# GameObjectList not Setting Parent 0 Answers

C# The call is ambiguous between the following methods or properties 1 Answer

C# Smoothing Out transform.Translate 4 Answers

C# GUI.Button Transform.Position 1 Answer

C# Need Help Refining Ricochet Script 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