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 /
This question was closed Oct 30, 2013 at 08:52 PM by WhipJr for the following reason:

commands.close.hint.6

avatar image
0
Question by WhipJr · Aug 18, 2011 at 01:14 AM · booleanfloatsyntax-errorcs0029

help with a random battle generator?

i am making a gale that is gonna consist of a battle system unlike any other. but i have to start at the beginning to even start making it into what i want it, and the beginning is a little more complicated than i originally intended.

i started my scripting already on making the random battles happen, but for my first problem i keep getting this error:

Assets/FPS RPG_Scripts/RandomEncounterScript.cs(21,17): error CS0029: Cannot implicitly convert type 'float' to 'bool'

with this code:

 using UnityEngine;

using System.Collections;

public class RandomEncounterScript : MonoBehaviour {

 private int RN;
 public bool randEncounter;
 public bool inBattle;
 
 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
 
     RN = Random.Range(1, 10);
     
     if (Input.GetAxis("L_U D")){
     if(RN > 4){    
             if(RN < 7){
         Debug.Log ("battle");
             }
         }
     }
 }

}

and my second problem. this is going to load another level called battle or something and after the battle is finished i want to have my character resume from the exact same spot as before the random battle occured. how can i cache or store the player coordinates on the map that it was on before the battle?

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

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by djmorrsee · Aug 18, 2011 at 01:34 AM

As for your first question, Input.GetAxis returns always returns a float value (and always exists) between -1 and 1. As I'm not sure what your intentions were with that line, its hard to suggest a workaround. You would need to do something like

 if(Input.GetAxis("L_U D") > 0){  //Moving to left (or right?)
 or
 if(Input.GetAxis("L_U D") != 0){ //axis is tilted

Again, its hard to say without knowing what you were trying to do. For your second question, look into Object.DontDestroyOnLoad(). Saving an empty object with a script that gets your player.transform.position when the scene changes, then applies it when the scene comes back should work. Personally, I've never worked with DontDestroyOnLoad, but it should work.

EDIT: I was ninja'd....

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 WhipJr · Aug 18, 2011 at 01:45 AM 0
Share

thanks for the advice, for the first part of your response:

this is gonna go on the player "L_U D" stands for Left Stick Up Down so when the stick moves up or down check RN (Random Number) if its less than 7 and greater than 4. if so then "Battle" is printed in the log.

as for your second part. its not moving the character to a new map its loading a completely new setting temporarily for the duration of the battle. loading a different character mesh and everything. much like Final Fantasy VII if you have ever played that. but in the battle everything is gonna be free roam like a CoD online game.

avatar image djmorrsee · Aug 18, 2011 at 03:06 AM 0
Share

So for the L_U D part, you would want if(Input.GetAxis("L_U D") != 0). I'm unsure why you were getting the error you had commented on mgear's answer. Your sure there were no typo's?

Right I think i understand your idea. You'll be changing scenes correct? DontDestroyOnLoad will ensure that whatever object you pass as its argument will show up in your new scene. So you can store the location variable in a script, keep it through the battle, then when you go back, make sure it doesnt destroy again, then use that variable to set up your position. Sorry if im not explaining very well here, or just misunderstanding you completely.

As a side note, Update is called every frame. So even on slower machines, you would average at the very least 20-30 frames per second. With the way you have the Random number working now, based on statistics, you would get a battle every 5 frames or so. So 4 battles per second, at the least. Just a small observation I made, that might be on purpose for testing reasons.

avatar image
0

Answer by mgear · Aug 18, 2011 at 01:19 AM

Havent used "Input.GetAxis" before, but it returns Float value, not boolean.

So, should be then:

 if (Input.GetAxis("L_U D")!=0){
Comment
Add comment · Show 1 · 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 WhipJr · Aug 18, 2011 at 01:22 AM 0
Share

now it says Operator !=' cannot be applied to operands of type string' and `int'

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Converting Variables 3 Answers

Compile Errors for Script 1 Answer

Login String to Bool Errors 1 Answer

Mathf.Lerp float between 0 and 1 based on boolean input 3 Answers

what the hell is a int? (or a float, or boolean, or string!) 3 Answers


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