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
1
Question by Daffyducky · Jun 09, 2012 at 04:00 PM · transformdestroyremote

Controlling waterlevels in room after mousedown on different object

Hi there, ive only been scripting for 2 weeks now but im running into a problem i cannot fix. Ive got this room with water on the floor and a hatch under the waterlevel. in order to open the hatch, the player needs to look for a solution to drop the waterlevel. This is done by pushing the correct code on a device. Now i figured out how to make the device... and at the moment were the water needs to drop i can play a sound. But how can i get the waterlevel to drop?

I guess i would need to make unity use the waterplane (tags???) and make this transform OR destory the waterplane itself... I know how to destoy objects or player itself on collision. But this new problem is kind of a remote situation... How do i tell unity wich object to transform or destroy from within my device-script? (after button is pressed)

Any help would be great, Still studying on all the rest of my problems, but this one is giving me a headache Kind regards Tommy

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by aldonaletto · Jun 09, 2012 at 04:14 PM

A simple way is to keep a waterLevel float variable that holds the desired water level (waterplane Y coordinate) and make the waterplane follow it at some specific speed. When you want to lower the water level, just subtract the desired height from the waterLevel variable and the water plane will gradually go down to reach the specified level (waterplane script):

var speed: float = 0.5; // speed in meters per second var waterLevel: float;

function Start(){ waterLevel = transform.position.y; // waterLevel starts at the current level }

function Update(){ // follow waterLevel at desired speed:
var pos = transform.position; pos.y = Mathf.MoveTowards(pos.y, waterLevel, speed * Time.deltaTime); transform.position = pos.y; }

// to lower 1.5m, for instance, just subtract 1.5 from waterLevel: waterLevel -= 1.5;

Comment
Add comment · 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
0

Answer by Daffyducky · Jun 10, 2012 at 11:33 AM

Ok, THANKS i read through this script and This is even better then what i had in mind (i was only thinking about an abrupt way of tranform, but your script gives me a smooth transaction). Only thing that im not sure about is were to attach this script... Do i place it on the waterplane itself and call it as a function from within the devices script - after correct code? (If so do i need to set the variables to static?) OR do i place this script inside my devices script - after correct code and use a tag to show the script that it needs to move a specific tagged waterplane? sorry for my noobish questions, im only at this for 2 weeks. (BIG BLUSH)

Comment
Add comment · 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
0

Answer by Daffyducky · Jun 10, 2012 at 11:40 AM

Little problem : i tried the script out, but unity gives me an error. "Assets/Scripting/Waterplane.js(14,28): BCE0022: Cannot convert 'float' to 'UnityEngine.Vector3' " --- it refers to line 14 transform.position = pos.y; --- Any idea ?

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Bug: cannot assign public Transform variable. Unity 2D 5.2 1 Answer

How to turn object into a particle system and back? 0 Answers

Destroy multiple gameObject as transform 0 Answers

Is "null" the best way to unparent a child? 1 Answer

Script problems... 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