Issue#384216: Unity - I'm trying to use this rotate code (almost solved, only 2 errors left)

  • What's wrong with this code I'm trying to use. It was a java script, but I want to understand it, so I tried to change it to C#, and I get 8 errors.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class scr_player_rotate : MonoBehaviour {
    5.  
    6.     Vector3 looktarget;
    7.     float turnSpeed = 20;
    8.     RaycastHit hit;
    9.     float point;
    10.  
    11.     void Update()
    12.     {
    13.  
    14.  
    15.         float ray = Camera.ScreenPointToRay(Input.mousePosition);
    16.         float hit = RaycastHit;
    17.         if...
    I'm trying to use this rotate code (almost solved, only 2 errors left)

    0 Answers

    Sorry, your answer is too short !

  • Issue#384377: Unity - I'm trying to use this rotate code (solved, thanks)

    What's wrong with this code I'm trying to use. It was a java script, but I want to understand it, so I tried to change it to C#, and I get 8 errors. Code (CSharp): using UnityEngine; using System.Collections;   public class scr_player_rotate : MonoBehaviour {       Vector3 looktarget;     float turnSpeed = 20;     RaycastHit hit;     float point;       void Update()     {             float ray = Camera.ScreenPointToRay(Input.mousePosition);         float hit = RaycastHit;         if... I'm trying to use this rotate code (solved, thanks)

  • Issue#3197: Unity - [SOLVED]Help Condensing Code For Efficiency

    I am not sure how simple or complex this will be but, help is much appreciated. I want to be able to condense this into one function that will work for as many characters as I choose to add. Right now I am applying each function to is respective UI button. I feel like there is a more efficient way of writing this rather than copying and pasting 20+ times. Code (CSharp): public void ChooseCharacterOne(){         //characterOneActive = !characterOneActive;         if (characterOneActive ==... [SOLVED]Help Condensing Code For Efficiency

  • Issue#10382: Unity errors when compiling valid code - what version of C# language is supported?

    Hello everybody! I started working with Unity recently, but I have many years of experience in multiple programming languages, and I'm always trying to utilize maximum of advanced features of the language. I discovered there are some expressions which are valid C# code, but Unity has trouble compiling it, so I'm assuming those are newer language features which Unity can't comprehend. When it happened first time, I just ignored it, but since I found multiple occurrences of this thing, I... Unity errors when compiling valid code - what version of C# language is supported?

  • Issue#62716: Unity - [Solved] Diagonal movement speed issue

    Hello. I am attempting to move my player up, down, left, and right on a 2d plane. However, I was getting what is apparently a common issue where diagonal movement was compounded by 2 different vectors equalling more than 1. The solution, apparently, is to normalize the vectors and then use those normalized vectors to move the object at the end of the function. The problem I am having now is that I can no longer move up or down, it only allows me to move left or right, and I can't figure out... [Solved] Diagonal movement speed issue

  • Issue#63536: Unity - rigidbody.Rotate() extension methods. [Free code]

    Hi, I've wrote rigidbody.Rotate() extension methods, and wanted to share. The methods are trying to have same effect as transform.Rotate() methods but uses rigidbody.MoveRotation() so that objects take into account the Rigidbody's interpolation setting. Please, let me know if I've done any errors. Or if there is better way to do things. Code (CSharp):         public static void Rotate(this Rigidbody rigidbody, float xAngle, float yAngle, float zAngle, Space relativeTo=Space.Self) {... rigidbody.Rotate() extension methods. [Free code]

  • Issue#70018: Asus - Q Code 99 issue and how I solved it.

    This is my first high endish gaming computer, my old Asus G51 was not playing games on high or even medium well anymore so I decided to upgrade and thats what leads to this post. Here is my setup. VIII Hero Motherboard I5-6600K Gskill 32Gb Ram 4x8 WD 1TB HD 1 DVD Drive CoolerMaster Hyper 212 Fractal R5 Gaming case Evga Supernova 750 PSU XFX R9 390 I installed everything over a full day carefully putting everything in its place and hooking up the correct wires, everything looked amamazing and I was ready for the first boot up. I press the bootup button and it lights up with beautiful fan and MB led lights. It goes through the codes all the way up to Q 99 with the Boot LED lit then the fans slow down and nothing...No display, no beeps, just...nothing. Hmm thats weird. So I try it a few more times and the same issue. I talk to asus support and realize that my RAM is not on the QVL (Although GSKILL says it will work). They say I need to RMA it. I decided to order some QVL Ram and have

  • Issue#106031: Unity - Visual Studio 2015 small code window issue

    Hi all, Hope you can help, I have moved to MVS for coding but I have come into an issue which is driving me crazy. For some reason there is a large gap between my code and the side of the window and I'm sure it wasn't there before. It looks like all my code is indented when its not. I also want to get rid of the these +/- signs which I can only do with the keyboard shortcut (CTRL M +P). Anyone know where I can set these to off and move my code so its against the edge of the window? Thanks... Visual Studio 2015 small code window issue

  • Issue#114450: Unity - [SOLVED] Rotate camera on z-axis when x-axis rotation is 90 degrees

    I am making a little tilt marble labyrinth game as my first Unity project, and I am trying to get the camera to rotate simulating the act of tilting the game table. The camera is rotated at x = 90, y = 0, z = 0). This causes it to look directly at the center of the game board beneath. Rotating along the x axis works as expected with vertical input, but rotating along the z-axis simply spins the camera rather than rotate on its relative z axis -- and I understand why. Since the camera is... [SOLVED] Rotate camera on z-axis when x-axis rotation is 90 degrees

  • Issue#117446: Unity - right analogue stick doesn't code the same as the left

    I can code fine for the left joystick (movement etc) but I can only get the right joystick to make something move on the x axis and even then when the stick is back in the middle it still makes it move. Is there any documentation on this? I haven't been able to find any or could someone here help? if so, thanks

  • Issue#192297: Unity - 2D Hookshot Rotation issue with Raycast (Solved)

    Hi! I'm currently working on a 2D game where the hookshot is one of the main gameplay element/mechanic. The grappling will draw the player toward the end point, a bit like link grappling hook. It's working but it is not precise. There is an issue. The line of the raycast does not have the same angle of the line renderer I'm using as a grappling. I've been looking for what's wrong with this code for a while but can't get my head around it. I'm sure it's a stupid little error that is screwing... 2D Hookshot Rotation issue with Raycast (Solved)

  • Issue#196468: Unity - [Solved] Rotate car wheels to match 360 steering wheel

    Hey, Im new to unity, and im sure this question may have been asked before. I have found severaly similar questions but cannot find a solution to my problem. I have a car, and a steering wheel controller. (the scene is top down (but still 3d)). I want the car to rotate its wheels left/right to face the car in the same direction as the steering wheel (i.e if the steering wheel is pointing south, the car shoud turn its wheels and eventually face south). I thought about getting the cars... [Solved] Rotate car wheels to match 360 steering wheel

  • Issue#223233: Unity - [Solved] Code not working after update

    This code was working fine before the update (5.2 to 5.3) and now it's not working as intended and I can't figure out why. This code instantiates a bar at a certain position (Flow Bar Bit Start) before the update, but now it just instantiates at the middle of the screen (objectPos). I can't figure out why, has the update messed with anything? Code (csharp):         //flowBar     public static int flow;     private int flowBits = 80;     public int flowBitNumber;     public int flowBitOpacity;... [Solved] Code not working after update

  • Issue#225096: Unity - [SOLVED] Can't rotate object with script

    Hello, i have a problem with one of my script. I'm trying to make closable/openable doors. Everything works except one thing: Only the Collider rotate, the model of the door don't move :/ Code (JavaScript): var smooth : float = 2.0f; var DoorOpenAngle : float = 90.0f; var DoorCloseAngle : float = 0.0f; var open : boolean; var enter : boolean; var OpenDoorSound : AudioClip; var ASource : AudioSource;   function Update() {     if (open == true) {         var target = Quaternion.Euler (0,... [SOLVED] Can't rotate object with script

  • Issue#238209: Unity - Player sprite cannot rotate left, move forward and shoot at the same time!

    Hello, I'm wondering why is it that if I hold the left arrow button (or 'A') to rotate the player left, up arrow to move forward, then hold the shoot button (space), I can't shoot but I can still rotate? Also, when I hold the up arrow first, then shoot, then hold the left arrow, the player seems to get 'locked', it keeps going forward (and never rotates). Basically, there's seem to be a problem involving rotating left, moving forward and shooting at the same time. If I just stand still and... Player sprite cannot rotate left, move forward and shoot at the same time!

  • Issue#295270: Unity - Help with code. Can't find answer to be beginner issue.

    Hello, I'm practicing C# by following a video about creating the game 2048. Very early on, it is needed for 2 scripts to talk to each other, I'm following the steps exactly as they are shown, but I'm getting an error that it's beyond my knowledge. Code (CSharp): using UnityEngine; using System.Collections;   public class InputManager : MonoBehaviour {     public enum MoveDirection     {         Left, Right, Up, Down     }       private GameManager gm;       void Awake()     {         gm =... Help with code. Can't find answer to be beginner issue.

  • Issue#296103: Unity - [SOLVED] Serialized fields aren't being updated in inspector when re-compile source code

    I have noticed that this issue keeps happening. You create a script with a serialized field: Code (csharp):   [SerializeField] private float roomRealtimeLightShadowStrengthHigh = 1.0f; //100% strength   If you compile the code, then variable is exposed in the inspector Now, if you go to the source code and change the value, Code (csharp):   [SerializeField] private float roomRealtimeLightShadowStrengthHigh = 0.9f; //90% strength   the value is not updated in the inspector. The inspector still... [SOLVED] Serialized fields aren't being updated in inspector when re-compile source code

  • Issue#344823: Unity - (Solved) How to turn a simple rotate to a smooth one?

    Hi all, I have a simple code to rotate an object. Code (CSharp): void RotateMode()     {         if (Input.GetKeyDown (KeyCode.LeftArrow))             LeftKey();         if (Input.GetKeyDown (KeyCode.RightArrow))             RightKey();     }       void LeftKey()     {         transform.Rotate(new Vector3(0, 0, 90));         theTurnCounter.turnsAllowed = theTurnCounter.turnsAllowed -1;     }       void RightKey()     {         transform.Rotate(new Vector3(0, 0, -90));... (Solved) How to turn a simple rotate to a smooth one?

  • Issue#381167: Unity - I'm trying to use this rotate code

    What's wrong with this code I'm trying to use. It was a java script, but I want to understand it, so I tried to change it to C#, and I get 8 errors. Code (CSharp): using UnityEngine; using System.Collections;   public class scr_player_rotate : MonoBehaviour {       Vector3 looktarget;     float turnSpeed = 20;     RaycastHit hit;     float point;       void Update()     {             float ray = Camera.ScreenPointToRay(Input.mousePosition);         float hit = RaycastHit;         if... I'm trying to use this rotate code

  • Issue#394531: Unity - EXP/Level system help fix code [SOLVED]

    I am trying to create a level system for my game, but i quickly found out I cannot "math" today and have no idea why this is not working. Code (CSharp): public static void ZepherAddExp(int EXP){         CharacterInformation.ZepherCurrentEXP += EXP;         Debug.Log ("Zepher gained " + EXP + " EXP!");         for (int i = CharacterInformation.ZepherCurrentEXP; i >= CharacterInformation.ZepherNeededEXP; i -= CharacterInformation.ZepherNeededEXP) {             CharacterInformation.ZepherLevel... EXP/Level system help fix code [SOLVED]

  • Issue#426917: Unity - [Solved] Why is this Spawn Code Spawning Two Objects?

    Hello everyone not sure why my code is spawning two objects at once rather than spawning only one at a time? Please advise. Code (CSharp): using System.Collections;     public class SpawnerInParent : MonoBehaviour {       public GameObject[] testObject;     public float xRange = 1.0f;     public float yRange = 1.0f;     public float minSpawnTime = 1.0f;     public float maxSpawnTime = 10.0f;       // Use this for initialization     public void Start ()          {         Invoke ("SpawnItem",... [Solved] Why is this Spawn Code Spawning Two Objects?

  • Issue#429925: Unity made it's own code throw errors?

    I got an AI character that is supposed to walk to a waypoint and go to randoms at each time it finished it's path. * The animation wont work, (24/7 Idle is not what I want....) * If the player bumps into the AI, he floats away and wont return to the path it's following * Upon arrival, the AI stops and dont go any furthur I took this screenshot from the Console: View attachment 181021 How does this happend and how can I make it work? :c

  • Issue#539331: Unity - Null reference code but no errors before running

    Got a null reference to my script but not sure what the problem is because I don't show any errors before running the game. Here's the line I've got: Code (csharp): if (item.itemType != Item.ItemType.None) This is the first line of code in my update function. I can't quite figure out what the problem is, mostly because coding is not easy. I'm following a tutorial series for making an inventory system. This is the final video of the series: I can't find... Null reference code but no errors before running

  • Issue#554763: Unity - [SOLVED] Part of my code not running the second time.

    Hi, So I made a function that initialy spawns an ammo pack prefab after an interval. Code (CSharp):   using UnityEngine; using System.Collections;   /// <summary> /// SG /// You can add item prefabs and spawnlocations, set a delay between spawn and the place / item is random /// </summary> public class PickupSpawner : MonoBehaviour {     public static PickupSpawner _ps;     public float pickupDeliveryTimeMin = 10f;       // Delay on delivery.     public float pickupDeliveryTimeMax = 30f;... [SOLVED] Part of my code not running the second time.

  • Issue#562939: Unity - How to I get the Input Code/Axis for the Xbox Controller Left/Right Bumper?

    At the moment I am perfectly able to get button codes for the keyboard and xbox buttons however I have no idea what the codes are to access whether the xbox bumper button is pressed? At the moment I have: Code (CSharp):         if (other.gameObject.tag == "Tricycle" && !trInteracted && Input.GetKey ("joystick button 2"))         {             //Do Stuff! So this works with the xbox "B" button but how would I get this to work with the L/R bumper? Thanks in advance!

  • Issue#585565: Unity - Weird Issue - Solved

    Hi there, this is probably something really stupid am just not seeing but am having a issue. for some reason Back,Left and Down are refusing to register even thou the block rotations are correct I should point out that the blocks are children of another object hence the use of Local rotation. I find it weird that Forward,Right and Up are all working correct. Please help my head hurt. Thanks in advance =) Code (CSharp):         Debug.Log(Block.localRotation.eulerAngles.y);         if... Weird Issue - Solved

  • Issue#620362: Unity - [SOLVED]Why doesn't this code work?

    I have a line of code that works perfectly: Code (CSharp): gameCamera.GetComponent<CameraController>().cameraTarget = SelectedPlayer.transform; I then have this code that should do the same thing: Code (CSharp): gameCamera.GetComponent<CameraController>().cameraTarget = army.selectedArmy[character].gameObject.transform; In the second line I am trying to get the camera to focus on a game object by clicking a UI button and it focuses on an object depending on it position in the list... [SOLVED]Why doesn't this code work?

  • Issue#620473: Unity - issue with code not working

    Hello all, I've been googling and searching around on the forums here for a bit, but I cant really get a solid answer so I figured id make a post. Im new to unity, and new to C#. Im currently working on the rollerball tutorial, and im having problems with the movement script. While googling I found another person copy/paste his script, and it worked. The problem im having is understanding why his did, and mine doesnt. When I compare the two scripts side by side, the only difference I can... issue with code not working

  • Issue#629722: Unity - [SOLVED] Tackling the issue of spawning non-player objects from non-player objects.

    I plan to have players spawn non-player objects from other non-player objects into the scene. The issue is that non-player objects do not have Client Authority Owners or specific Connection To Client or Connect to Server. Code (CSharp):     private void AddingNewSplitGroup() {         foreach (GameObject obj in this.selectionManager.selectedObjects) {             NetworkIdentity identity = obj.GetComponent<NetworkIdentity>();             Debug.Log("Calling on CmdSplit()");... [SOLVED] Tackling the issue of spawning non-player objects from non-player objects.

  • Issue#677382: Unity - [SOLVED] How to display messages in the error console, but continue code execution

    I'm trying to intentionally display certain debug logs in the error console window just so they stand out more during debugging. I have: Code (csharp):     public void Start() {      Debug.Log("Here 1");      SpecialLog("The player opened the door");      Debug.Log ("Here 2"); }     public void SpecialLog(string msg)    {         System.Exception e = new System.Exception(msg);         throw e;    }   The message is displayed in the error console. But, code execution stops because the exception... [SOLVED] How to display messages in the error console, but continue code execution