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");
}
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...
Converted to comment since it's not an answer one of the script is Java and the other one is C#
Your answer
Follow this Question
Related Questions
Could someone translate these to c#? 1 Answer
addComponent c# script by java 0 Answers
JavaScript Problem - BCE0043 - Unexpected Token Help 0 Answers
Clash of clans networking. 1 Answer