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 panos12 · Sep 08, 2015 at 03:37 PM · c#javascriptscript.scriptingbasicscompile

Need help to put together 2 scripts

Hi I want to put together these 2 scripts but I have no idea how can you help? using UnityEngine; using System.Collections;

 namespace OceanSurfaceEffects
 {
     /// <summary>
     /// Add to a game object to make it float on the water.
     /// This is just a rough method to demonstrate how to
     /// sample the wave height. You will likely need to 
     /// improve on this for a proper game.
     /// 
     /// There must a game object called Ocean with a Ocean script
     /// for this to work.
     /// </summary>
     public class AddBuoyancy : MonoBehaviour 
     {
         /// <summary>
         /// The m_ocean script.
         /// </summary>
         Ocean m_ocean;
 
         /// <summary>
         /// Increase the spread for wider objects.
         /// </summary>
         public float m_spread = 1.0f;
 
         /// <summary>
         /// Adjust offset to make the object float
         /// higher or lower in the water.
         /// </summary>
         public float m_offset = 0.0f;
 
         /// <summary>
         /// Increase to make the object tilt more.
         /// </summary>
         public float m_tilt = 20.0f;
 
         void Start() 
         {
 
             GameObject ocean = GameObject.Find("Ocean");
             
             if(ocean == null)
             {
                 Debug.Log("Could not find ocean game object");    
                 return;
             }
             
             m_ocean = ocean.GetComponent<Ocean>();
             
             if(m_ocean == null)
                 Debug.Log("Could not find ocean script");
         
         }
         
         void LateUpdate() 
         {
             if(m_ocean)
             {
                 Vector3 pos = transform.position;
 
                 float ht0 = m_ocean.SampleHeight(pos + new Vector3(m_spread,0,0));
                 float ht1 = m_ocean.SampleHeight(pos + new Vector3(-m_spread,0,0));
                 float ht2 = m_ocean.SampleHeight(pos + new Vector3(0,0,m_spread));
                 float ht3 = m_ocean.SampleHeight(pos + new Vector3(0,0,-m_spread));
                 
                 pos.y = (ht0+ht1+ht2+ht3)/4.0f + m_offset;
 
                 float dx = ht0 - ht1;
                 float dz = ht2 - ht3;
                 
                 transform.position = pos;
                 
                 transform.localEulerAngles = new Vector3(-dz*m_tilt,0,dx*m_tilt);
             }
         }
     }
 
 }

and the other one:

 var speed = 1.0;
 
 var acceleration = 1.0;
 
 var maxspeed = 2.0;
 
 var minspeed = -0.25;
 
 var heading = 0.0;
 
 var rudder = 0.0;
 
 var rudderDelta = 2.0;
 
 var maxRudder = 6.0;
 
 var bob = 0.1;
 
 var bobFrequency = 0.2;
 
 
 
 private var elapsed = 0.0;
 
 private var seaLevel = 0.0;
 
 private var rudderControl;
 
 private var rudderAngle = 0.0;
 
 
 
 function signedSqrt( x ){
 
     var r = Mathf.Sqrt(Mathf.Abs( x ));
 
     if( x < 0 ){
 
         return -r;
 
     } else {
 
         return r;
 
     }
 
 }
 
 
 
 function Update () {
 
     // Bobbing
 
     elapsed += Time.deltaTime;
 
     transform.position.y = seaLevel + bob * Mathf.Sin(elapsed * bobFrequency * (Mathf.PI * 2));
 
     
 
     // Steering
 
     rudder += Input.GetAxis("Horizontal") * rudderDelta * Time.deltaTime;
 
     if( rudder > maxRudder ){
 
         rudder = maxRudder;
 
     } else if ( rudder < -maxRudder ){
 
         rudder = -maxRudder;
 
     }
 
     heading = (heading + rudder * Time.deltaTime * signedSqrt(speed)) % 360;
 
     // transform.Rotate(0, rudder * Time.deltaTime, 0);
 
     transform.eulerAngles.y = heading;
 
     transform.eulerAngles.z = -rudder;
 
     
 
     if( rudderControl ){
 
         rudderAngle = ((-60 * rudder)/maxRudder + heading) % 360;
 
         //rudderControl.transform.localEulerAngles.y = (70 * rudderAngle) % 360;
 
         rudderControl.transform.eulerAngles = Vector3(0, rudderAngle, 0);
 
     }
 
     
 
     // Sail
 
     speed += Input.GetAxis("Vertical") * acceleration * Time.deltaTime;
 
     if( speed > maxspeed ){
 
         speed = maxspeed;
 
     } else if ( speed < minspeed ){
 
         speed = minspeed;
 
     }
 
     
 
      transform.Translate(-speed * Time.deltaTime,0,0);
 
 }
 
 
 
 function Awake (){
 
     seaLevel = transform.position.y;
 
     rudderControl = GameObject.Find("rudderControl");
 
 }
Comment
Add comment · Show 4
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 DiegoSLTS · Sep 08, 2015 at 05:30 PM 0
Share

What do you mean by "put together"? Do you want to make one unique script with both things? Or do you want to make both scripts work at the same time in your project?

You should give more details, right now any answer will be just guessing.

Also, what are those scripts supposed to do? Where did you get them? That's pretty important if you expect someone to help you...

avatar image Darkathion · Sep 10, 2015 at 11:27 PM 0
Share

Copy and Paste my friend its always the answer

avatar image Positive7 Darkathion · Sep 10, 2015 at 11:29 PM 0
Share

Converted to comment since it's not an answer one of the script is Java and the other one is C#

avatar image Darkathion Positive7 · Sep 10, 2015 at 11:31 PM 0
Share

oh sorry..

0 Replies

· Add your reply
  • Sort: 

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

32 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

Related Questions

Could someone translate these to c#? 1 Answer

addComponent c# script by java 0 Answers

How Do I change this Script to be JS, Anyone can help me, Please. I am still newbie about Unity. i am doing to work on my thesis, Hopefully it's gonna be done. Thank you so much in Advanced. 0 Answers

JavaScript Problem - BCE0043 - Unexpected Token Help 0 Answers

Clash of clans networking. 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